Bugzilla – Attachment 121165 Details for
Bug 26326
Add Koha Objects for Import Records and Import Record Matches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26326: (follow-up) Add ability to check for existence of any primary key
Bug-26326-follow-up-Add-ability-to-check-for-exist.patch (text/plain), 3.10 KB, created by
Nick Clemens (kidclamp)
on 2021-05-19 12:57:12 UTC
(
hide
)
Description:
Bug 26326: (follow-up) Add ability to check for existence of any primary key
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2021-05-19 12:57:12 UTC
Size:
3.10 KB
patch
obsolete
>From 354f92b53dabb0fcbad701774a2e43e8f7100970 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 30 Mar 2021 15:08:09 +0000 >Subject: [PATCH] Bug 26326: (follow-up) Add ability to check for existence of > any primary key > >Before dropping a primary key we need to see if one exists - this updates >the installer method to allow searching for existence of key >--- > C4/Installer.pm | 15 +++++++++------ > installer/data/mysql/atomicupdate/bug_26326.perl | 4 +++- > t/db_dependent/Installer.t | 4 ++-- > 3 files changed, 14 insertions(+), 9 deletions(-) > >diff --git a/C4/Installer.pm b/C4/Installer.pm >index 2d6b523eed..17570caccd 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -630,12 +630,15 @@ sub get_file_path_from_name { > sub primary_key_exists { > my ( $table_name, $key_name ) = @_; > my $dbh = C4::Context->dbh; >- my ($exists) = $dbh->selectrow_array( >- qq| >- SHOW INDEX FROM $table_name >- WHERE key_name = 'PRIMARY' AND column_name = ? >- |, undef, $key_name >- ); >+ my $sql = qq| SHOW INDEX FROM $table_name WHERE key_name='PRIMARY' |; >+ my $exists; >+ if( $key_name ){ >+ $sql .= 'AND column_name = ? ' if $key_name; >+ ($exists) = $dbh->selectrow_array( $sql, undef, $key_name ); >+ } else { >+ ($exists) = $dbh->selectrow_array( $sql, undef ); >+ } >+ > return $exists; > } > >diff --git a/installer/data/mysql/atomicupdate/bug_26326.perl b/installer/data/mysql/atomicupdate/bug_26326.perl >index b6a9c380fb..000aedc9f7 100644 >--- a/installer/data/mysql/atomicupdate/bug_26326.perl >+++ b/installer/data/mysql/atomicupdate/bug_26326.perl >@@ -4,7 +4,9 @@ if( CheckVersion( $DBversion ) ) { > primary_key_exists('import_record_matches','import_record_id') && > primary_key_exists('import_record_matches','candidate_match_id') > ){ >- $dbh->do( "ALTER TABLE import_record_matches DROP PRIMARY KEY" ); >+ if( primary_key_exists('import_record_matches' ) ){ >+ $dbh->do( "ALTER TABLE import_record_matches DROP PRIMARY KEY" ); >+ } > $dbh->do( "ALTER TABLE import_record_matches ADD PRIMARY KEY (import_record_id,candidate_match_id)" ); > } > >diff --git a/t/db_dependent/Installer.t b/t/db_dependent/Installer.t >index c8cbe6ceb7..c7daf48323 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 => 19; >+use Test::More tests => 20; > use File::Temp qw(tempfile); > use utf8; > >@@ -70,7 +70,7 @@ 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' ); > >- >+ok( primary_key_exists( 'borrowers' ), 'Borrowers does have a primary key on some column'); > ok( primary_key_exists( 'borrowers', 'borrowernumber'), 'Borrowers has primary key on borrowernumber'); > ok( ! primary_key_exists( 'borrowers', 'email'), 'Borrowers does not have a primary key on email'); > >-- >2.11.0
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 26326
:
109373
|
114817
|
118974
|
119017
|
120992
|
120993
|
121164
|
121165
|
121166
|
121199
|
121200
|
121201
|
124171
|
124172
|
124173
|
126979
|
127165
|
127166
|
127167
|
127168
|
127257
|
127258
|
127259