Bugzilla – Attachment 110114 Details for
Bug 26325
Add primary_key_exists function to Installer.pm
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26325: Add primary_key_exists check to C4::Installer
Bug-26325-Add-primarykeyexists-check-to-C4Installe.patch (text/plain), 2.15 KB, created by
Brandon J
on 2020-09-15 15:57:45 UTC
(
hide
)
Description:
Bug 26325: Add primary_key_exists check to C4::Installer
Filename:
MIME Type:
Creator:
Brandon J
Created:
2020-09-15 15:57:45 UTC
Size:
2.15 KB
patch
obsolete
>From 4662a1c5632246f3396c24c82f5ff26be745a4c8 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 31 Aug 2020 16:43:53 +0000 >Subject: [PATCH] Bug 26325: Add primary_key_exists check to C4::Installer > >To test: >1 - prove -v t/db_dependent/Installer.t > >Signed-off-by: Brandon J <brandon.jimenez@inLibro.com> >--- > C4/Installer.pm | 14 +++++++++++++- > t/db_dependent/Installer.t | 6 +++++- > 2 files changed, 18 insertions(+), 2 deletions(-) > >diff --git a/C4/Installer.pm b/C4/Installer.pm >index 3624d13226..55bcf27335 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -30,7 +30,7 @@ use vars qw(@ISA @EXPORT); > BEGIN { > require Exporter; > @ISA = qw( Exporter ); >- push @EXPORT, qw( foreign_key_exists index_exists column_exists TableExists); >+ push @EXPORT, qw( primary_key_exists foreign_key_exists index_exists column_exists TableExists); > }; > > =head1 NAME >@@ -610,6 +610,18 @@ 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 >+ ); >+ return $exists; >+} >+ > sub foreign_key_exists { > my ( $table_name, $constraint_name ) = @_; > my $dbh = C4::Context->dbh; >diff --git a/t/db_dependent/Installer.t b/t/db_dependent/Installer.t >index 7ba654d62f..be3bc350a9 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 => 16; >+use Test::More tests => 18; > use Koha::Database; > > BEGIN { >@@ -66,3 +66,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', 'borrowernumber'), 'Borrowers has primary key on borrowernumber'); >+ok( ! primary_key_exists( 'borrowers', 'email'), 'Borrowers does not have a primary key on email'); >-- >2.17.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 26325
:
109372
|
110114
|
110124