Koha/installer/data/mysql/db_revs/210600018.pl
Jonathan Druart 2b083cb82a Bug 22690: DBRev 21.06.00.018
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-08-27 15:28:23 +02:00

25 lines
1.4 KiB
Perl
Executable file

use Modern::Perl;
return {
bug_number => "22690",
description => "Add contraints to the linktracker table",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
unless( foreign_key_exists( 'linktracker', 'linktracker_biblio_ibfk' ) ) {
$dbh->do(q{ UPDATE linktracker SET biblionumber = NULL WHERE biblionumber NOT IN (SELECT biblionumber FROM biblio) });
$dbh->do(q{ ALTER TABLE linktracker ADD CONSTRAINT `linktracker_biblio_ibfk` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE SET NULL });
}
unless( foreign_key_exists( 'linktracker', 'linktracker_item_ibfk' ) ) {
$dbh->do(q{ UPDATE linktracker SET itemnumber = NULL WHERE itemnumber NOT IN (SELECT itemnumber FROM items) });
$dbh->do(q{ ALTER TABLE linktracker ADD CONSTRAINT `linktracker_item_ibfk` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL });
}
unless( foreign_key_exists( 'linktracker', 'linktracker_borrower_ibfk' ) ) {
$dbh->do(q{ UPDATE linktracker SET borrowernumber = NULL WHERE borrowernumber NOT IN (SELECT borrowernumber FROM borrowers) });
$dbh->do(q{ ALTER TABLE linktracker ADD CONSTRAINT `linktracker_borrower_ibfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE SET NULL });
}
},
}