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

(-)a/C4/Installer.pm (-6 / +9 lines)
Lines 632-643 sub get_file_path_from_name { Link Here
632
sub primary_key_exists {
632
sub primary_key_exists {
633
    my ( $table_name, $key_name ) = @_;
633
    my ( $table_name, $key_name ) = @_;
634
    my $dbh = C4::Context->dbh;
634
    my $dbh = C4::Context->dbh;
635
    my ($exists) = $dbh->selectrow_array(
635
    my $sql = qq| SHOW INDEX FROM $table_name WHERE key_name='PRIMARY' |;
636
        qq|
636
    my $exists;
637
        SHOW INDEX FROM $table_name
637
    if( $key_name ){
638
        WHERE key_name = 'PRIMARY' AND column_name = ?
638
        $sql .= 'AND column_name = ? ' if $key_name;
639
        |, undef, $key_name
639
        ($exists) = $dbh->selectrow_array( $sql, undef, $key_name );
640
    );
640
    } else {
641
        ($exists) = $dbh->selectrow_array( $sql, undef );
642
    }
643
641
    return $exists;
644
    return $exists;
642
}
645
}
643
646
(-)a/installer/data/mysql/atomicupdate/bug_26326.perl (-1 / +3 lines)
Lines 4-10 if( CheckVersion( $DBversion ) ) { Link Here
4
        primary_key_exists('import_record_matches','import_record_id') &&
4
        primary_key_exists('import_record_matches','import_record_id') &&
5
        primary_key_exists('import_record_matches','candidate_match_id')
5
        primary_key_exists('import_record_matches','candidate_match_id')
6
    ){
6
    ){
7
        $dbh->do( "ALTER TABLE import_record_matches DROP PRIMARY KEY" );
7
        if( primary_key_exists('import_record_matches' ) ){
8
            $dbh->do( "ALTER TABLE import_record_matches DROP PRIMARY KEY" );
9
        }
8
        $dbh->do( "ALTER TABLE import_record_matches ADD PRIMARY KEY (import_record_id,candidate_match_id)" );
10
        $dbh->do( "ALTER TABLE import_record_matches ADD PRIMARY KEY (import_record_id,candidate_match_id)" );
9
    }
11
    }
10
12
(-)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 => 21;
25
use Test::More tests => 22;
26
use File::Temp qw(tempfile);
26
use File::Temp qw(tempfile);
27
use utf8;
27
use utf8;
28
28
Lines 70-79 ok( ! index_exists( 'borrowers', 'xxx'), 'Constraint xxx does not exist' ); Link Here
70
ok( foreign_key_exists( 'borrowers', 'borrowers_ibfk_1' ), 'FK borrowers_ibfk_1 exists' );
70
ok( foreign_key_exists( 'borrowers', 'borrowers_ibfk_1' ), 'FK borrowers_ibfk_1 exists' );
71
ok( ! foreign_key_exists( 'borrowers', 'xxx' ), 'FK xxxx does not exist' );
71
ok( ! foreign_key_exists( 'borrowers', 'xxx' ), 'FK xxxx does not exist' );
72
72
73
<<<<<<< HEAD
73
ok( unique_key_exists( 'items', 'itembarcodeidx' ), 'UNIQUE KEY itembarcodeidx exists' );
74
ok( unique_key_exists( 'items', 'itembarcodeidx' ), 'UNIQUE KEY itembarcodeidx exists' );
74
ok( ! unique_key_exists( 'borrowers', 'xxx' ), 'UNIQUE KEY xxxx does not exist' );
75
ok( ! unique_key_exists( 'borrowers', 'xxx' ), 'UNIQUE KEY xxxx does not exist' );
75
76
76
77
78
=======
79
ok( primary_key_exists( 'borrowers' ), 'Borrowers does have a primary key on some column');
80
>>>>>>> Bug 26326: (follow-up) Add ability to check for existence of any primary key
77
ok( primary_key_exists( 'borrowers', 'borrowernumber'), 'Borrowers has primary key on borrowernumber');
81
ok( primary_key_exists( 'borrowers', 'borrowernumber'), 'Borrowers has primary key on borrowernumber');
78
ok( ! primary_key_exists( 'borrowers', 'email'), 'Borrowers does not have a primary key on email');
82
ok( ! primary_key_exists( 'borrowers', 'email'), 'Borrowers does not have a primary key on email');
79
83
80
- 

Return to bug 26326