From a6fc688ab59a5396e8dbd6d869606ead7680a222 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 20 Dec 2023 10:35:17 +0100 Subject: [PATCH] Bug 35610: Add FK on old_reserves.branchcode --- installer/data/mysql/atomicupdate/bug_35610.pl | 18 ++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + 2 files changed, 19 insertions(+) create mode 100755 installer/data/mysql/atomicupdate/bug_35610.pl diff --git a/installer/data/mysql/atomicupdate/bug_35610.pl b/installer/data/mysql/atomicupdate/bug_35610.pl new file mode 100755 index 00000000000..e9e2c107251 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_35610.pl @@ -0,0 +1,18 @@ +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{ + 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'" + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 0b59ad8d85c..c497ce77a73 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4917,6 +4917,7 @@ CREATE TABLE `old_reserves` ( CONSTRAINT `old_reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL, CONSTRAINT `old_reserves_ibfk_4` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE SET NULL ON UPDATE SET NULL, CONSTRAINT `old_reserves_ibfk_ig` FOREIGN KEY (`item_group_id`) REFERENCES `item_groups` (`item_group_id`) ON DELETE SET NULL ON UPDATE SET NULL + CONSTRAINT `old_reserves_ibfk_branchcode` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- 2.34.1