Bugzilla – Attachment 127171 Details for
Bug 29336
Some authorised_value FKs are too short
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29336: Allow to check on FK existence with field name
Bug-29336-Allow-to-check-on-FK-existence-with-fiel.patch (text/plain), 2.19 KB, created by
Marcel de Rooy
on 2021-11-01 14:14:40 UTC
(
hide
)
Description:
Bug 29336: Allow to check on FK existence with field name
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2021-11-01 14:14:40 UTC
Size:
2.19 KB
patch
obsolete
>From 66f421529c054eac9895f4093829d2951d6e0ac6 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Mon, 1 Nov 2021 14:08:42 +0000 >Subject: [PATCH] Bug 29336: Allow to check on FK existence with field name >Content-Type: text/plain; charset=utf-8 > >Sometimes easier (or even safer) to check for FK on specific >field name rather than constraint name (which may be created >automatically). > >Test plan: >Run t/db_dependent/Installer.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > C4/Installer.pm | 5 +++-- > t/db_dependent/Installer.t | 4 +++- > 2 files changed, 6 insertions(+), 3 deletions(-) > >diff --git a/C4/Installer.pm b/C4/Installer.pm >index 65bb578e1a..f972940028 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -642,10 +642,11 @@ sub primary_key_exists { > } > > sub foreign_key_exists { >- my ( $table_name, $constraint_name ) = @_; >+ my ( $table_name, $constraint_name, $field_name ) = @_; > my $dbh = C4::Context->dbh; > my (undef, $infos) = $dbh->selectrow_array(qq|SHOW CREATE TABLE $table_name|); >- return $infos =~ m|CONSTRAINT `$constraint_name` FOREIGN KEY|; >+ return $infos =~ m|CONSTRAINT `$constraint_name` FOREIGN KEY| if $constraint_name; >+ return $infos =~ m|FOREIGN KEY \(`$field_name`\)| if $field_name; > } > > sub unique_key_exists { >diff --git a/t/db_dependent/Installer.t b/t/db_dependent/Installer.t >index 15e2985af8..2a1421de1c 100755 >--- a/t/db_dependent/Installer.t >+++ b/t/db_dependent/Installer.t >@@ -22,7 +22,7 @@ > # Add more tests here!!! > > use Modern::Perl; >-use Test::More tests => 21; >+use Test::More tests => 22; > use File::Temp qw(tempfile); > use utf8; > >@@ -69,6 +69,8 @@ ok( ! index_exists( 'borrowers', 'xxx'), 'Constraint xxx does not exist' ); > > ok( foreign_key_exists( 'borrowers', 'borrowers_ibfk_1' ), 'FK borrowers_ibfk_1 exists' ); > ok( ! foreign_key_exists( 'borrowers', 'xxx' ), 'FK xxxx does not exist' ); >+# test new third parameter: >+ok( foreign_key_exists( 'borrowers', undef, 'categorycode' ), 'FK on categorycode exists' ); > > ok( unique_key_exists( 'items', 'itembarcodeidx' ), 'UNIQUE KEY itembarcodeidx exists' ); > ok( ! unique_key_exists( 'borrowers', 'xxx' ), 'UNIQUE KEY xxxx does not exist' ); >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29336
:
127051
|
127052
|
127053
|
127169
|
127170
|
127171
|
127172
|
128655
|
128656
|
129187
|
129188
|
129189