View | Details | Raw Unified | Return to bug 26325
Collapse All | Expand All

(-)a/C4/Installer.pm (-1 / +13 lines)
Lines 30-36 use vars qw(@ISA @EXPORT); Link Here
30
BEGIN {
30
BEGIN {
31
    require Exporter;
31
    require Exporter;
32
    @ISA = qw( Exporter );
32
    @ISA = qw( Exporter );
33
    push @EXPORT, qw( foreign_key_exists index_exists column_exists TableExists);
33
    push @EXPORT, qw( primary_key_exists foreign_key_exists index_exists column_exists TableExists);
34
};
34
};
35
35
36
=head1 NAME
36
=head1 NAME
Lines 604-609 sub get_file_path_from_name { Link Here
604
604
605
}
605
}
606
606
607
sub primary_key_exists {
608
    my ( $table_name, $key_name ) = @_;
609
    my $dbh = C4::Context->dbh;
610
    my ($exists) = $dbh->selectrow_array(
611
        qq|
612
        SHOW INDEX FROM $table_name
613
        WHERE key_name = 'PRIMARY' AND column_name = ?
614
        |, undef, $key_name
615
    );
616
    return $exists;
617
}
618
607
sub foreign_key_exists {
619
sub foreign_key_exists {
608
    my ( $table_name, $constraint_name ) = @_;
620
    my ( $table_name, $constraint_name ) = @_;
609
    my $dbh = C4::Context->dbh;
621
    my $dbh = C4::Context->dbh;
(-)a/t/db_dependent/Installer.t (-2 / +5 lines)
Lines 22-28 Link Here
22
# Add more tests here!!!
22
# Add more tests here!!!
23
23
24
use Modern::Perl;
24
use Modern::Perl;
25
use Test::More tests => 16;
25
use Test::More tests => 18;
26
use Koha::Database;
26
use Koha::Database;
27
27
28
BEGIN {
28
BEGIN {
Lines 66-68 ok( ! index_exists( 'borrowers', 'xxx'), 'Constraint xxx does not exist' ); Link Here
66
66
67
ok( foreign_key_exists( 'borrowers', 'borrowers_ibfk_1' ), 'FK borrowers_ibfk_1 exists' );
67
ok( foreign_key_exists( 'borrowers', 'borrowers_ibfk_1' ), 'FK borrowers_ibfk_1 exists' );
68
ok( ! foreign_key_exists( 'borrowers', 'xxx' ), 'FK xxxx does not exist' );
68
ok( ! foreign_key_exists( 'borrowers', 'xxx' ), 'FK xxxx does not exist' );
69
- 
69
70
71
ok( primary_key_exists( 'borrowers', 'borrowernumber'), 'Borrowers has primary key on borrowernumber');
72
ok( ! primary_key_exists( 'borrowers', 'email'), 'Borrowers does not have a primary key on email');

Return to bug 26325