Bugzilla – Attachment 109372 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.10 KB, created by
Nick Clemens (kidclamp)
on 2020-08-31 16:44:59 UTC
(
hide
)
Description:
Bug 26325: Add primary_key_exists check to C4::Installer
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2020-08-31 16:44:59 UTC
Size:
2.10 KB
patch
obsolete
>From cc636c4429f39d850d7395747ee045dcbedbdd79 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 >--- > 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 db247e5243..f101cfca35 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 >@@ -604,6 +604,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 100644 >--- 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.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 26325
:
109372
|
110114
|
110124