Bugzilla – Attachment 155529 Details for
Bug 29390
Authorised values: Add a few missing foreign keys
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29390: Allow to check on FK existence with field name
Bug-29390-Allow-to-check-on-FK-existence-with-fiel.patch (text/plain), 2.20 KB, created by
David Nind
on 2023-09-12 05:18:41 UTC
(
hide
)
Description:
Bug 29390: Allow to check on FK existence with field name
Filename:
MIME Type:
Creator:
David Nind
Created:
2023-09-12 05:18:41 UTC
Size:
2.20 KB
patch
obsolete
>From 7b5d5af0445aa8f21f929c2c23fe5de86f6028c3 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 29390: Allow to check on FK existence with field name > >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> >Signed-off-by: David Nind <david@davidnind.com> >--- > 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 7e248a17aa..5545908d01 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -648,10 +648,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 2e9c0e26c8..c8fc627aea 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 => 22; >+use Test::More tests => 23; > 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.30.2
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 29390
:
127214
|
127215
|
128985
|
152730
|
152731
|
152732
|
152733
|
152734
| 155529 |
155530
|
155531
|
155532
|
155533