From f9bcee4be87634716203ec45130824a6a8f407ae Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 10 Nov 2022 08:06:28 +0100 Subject: [PATCH] Bug 32162: Add primar key to erm_eholdings_packages_agreements Test plan: Confirm that this change fixes the related TestBuilder.t failure Confirm that it does not break the eRM app, try to attach an agreement to a package. Signed-off-by: Pedro Amorim Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- .../data/mysql/atomicupdate/bug_32162.pl | 24 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 4 ++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_32162.pl diff --git a/installer/data/mysql/atomicupdate/bug_32162.pl b/installer/data/mysql/atomicupdate/bug_32162.pl new file mode 100755 index 0000000000..acfecddd4e --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_32162.pl @@ -0,0 +1,24 @@ +use Modern::Perl; + +return { + bug_number => "31162", + description => "Add primary key to erm_eholdings_packages_agreements", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + unless ( primary_key_exists('erm_eholdings_packages_agreements') ){ + $dbh->do(q{ + ALTER TABLE erm_eholdings_packages_agreements + DROP FOREIGN KEY erm_eholdings_packages_agreements_ibfk_1, + DROP FOREIGN KEY erm_eholdings_packages_agreements_ibfk_2, + DROP CONSTRAINT erm_eholdings_packages_agreements_uniq, + ADD PRIMARY KEY(`package_id`, `agreement_id`) + }); + $dbh->do(q{ + ALTER TABLE erm_eholdings_packages_agreements + ADD CONSTRAINT `erm_eholdings_packages_agreements_ibfk_1` FOREIGN KEY (`package_id`) REFERENCES `erm_eholdings_packages` (`package_id`) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT `erm_eholdings_packages_agreements_ibfk_2` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE + }); + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 7015a95ff3..beb769937e 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2990,9 +2990,9 @@ DROP TABLE IF EXISTS `erm_eholdings_packages_agreements`; CREATE TABLE `erm_eholdings_packages_agreements` ( `package_id` INT(11) NOT NULL COMMENT 'link to the package', `agreement_id` INT(11) NOT NULL COMMENT 'link to the agreement', - UNIQUE KEY `erm_eholdings_packages_agreements_uniq` (`package_id`, `agreement_id`), CONSTRAINT `erm_eholdings_packages_agreements_ibfk_1` FOREIGN KEY (`package_id`) REFERENCES `erm_eholdings_packages` (`package_id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `erm_eholdings_packages_agreements_ibfk_2` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `erm_eholdings_packages_agreements_ibfk_2` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE, + PRIMARY KEY(`package_id`, `agreement_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- 2.39.5