Koha/installer/data/mysql/db_revs/231200015.pl
Katrin Fischer 56491caa5f
Bug 35610: DBRev 23.12.00.015
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
2024-04-04 15:24:26 +02:00

28 lines
887 B
Perl
Executable file

use Modern::Perl;
return {
bug_number => "35610",
description => "Add FK on old_reserves.branchcode",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
unless ( foreign_key_exists( 'old_reserves', 'old_reserves_ibfk_branchcode' ) ) {
$dbh->do(
q{
UPDATE old_reserves
SET branchcode = NULL
WHERE branchcode NOT IN (SELECT branchcode FROM branches)
}
);
$dbh->do(
q{
ALTER TABLE old_reserves
ADD CONSTRAINT `old_reserves_ibfk_branchcode` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE;
}
);
say $out "Added foreign key on 'old_reserves.branchcode'";
}
},
};