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 610-615 sub get_file_path_from_name { Link Here
610
610
611
}
611
}
612
612
613
sub primary_key_exists {
614
    my ( $table_name, $key_name ) = @_;
615
    my $dbh = C4::Context->dbh;
616
    my ($exists) = $dbh->selectrow_array(
617
        qq|
618
        SHOW INDEX FROM $table_name
619
        WHERE key_name = 'PRIMARY' AND column_name = ?
620
        |, undef, $key_name
621
    );
622
    return $exists;
623
}
624
613
sub foreign_key_exists {
625
sub foreign_key_exists {
614
    my ( $table_name, $constraint_name ) = @_;
626
    my ( $table_name, $constraint_name ) = @_;
615
    my $dbh = C4::Context->dbh;
627
    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