From 0204f2051872f82fdb8b701808c377d659b2676e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 8 Nov 2022 08:33:38 +0100 Subject: [PATCH] Bug 32030: Create erm_user_roles after erm_licenses Or the update will fail with the following error ERROR - {UNKNOWN}: DBI Exception: DBD::mysql::db do failed: Can't create table `koha_kohadev`.`erm_user_roles` (errno: 150 "Foreign key constraint is incorrectly formed") at /kohadevbox/koha/C4/Installer.pm line 739 Signed-off-by: Tomas Cohen Arazi --- installer/data/mysql/atomicupdate/erm.pl | 51 ++++++++++++------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/installer/data/mysql/atomicupdate/erm.pl b/installer/data/mysql/atomicupdate/erm.pl index 5f4475ca22..99ba899b0b 100755 --- a/installer/data/mysql/atomicupdate/erm.pl +++ b/installer/data/mysql/atomicupdate/erm.pl @@ -69,32 +69,6 @@ return { ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; }); } - - unless ( TableExists('erm_user_roles') ) { - $dbh->do(q{ - CREATE TABLE `erm_user_roles` ( - `agreement_id` INT(11) NULL COMMENT 'link to the agreement', - `license_id` INT(11) NULL COMMENT 'link to the license', - `user_id` INT(11) NOT NULL COMMENT 'link to the user', - `role` VARCHAR(80) NOT NULL COMMENT 'role of the user', - CONSTRAINT `erm_user_roles_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `erm_user_roles_ibfk_2` FOREIGN KEY (`license_id`) REFERENCES `erm_licenses` (`license_id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `erm_user_roles_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - }); - } - $dbh->do(q{ - INSERT IGNORE INTO authorised_value_categories (category_name, is_system) - VALUES - ('ERM_USER_ROLES', 1) - }); - $dbh->do(q{ - INSERT IGNORE INTO authorised_values (category, authorised_value, lib) - VALUES - ('ERM_USER_ROLES', 'librarian', 'ERM librarian'), - ('ERM_USER_ROLES', 'subject_specialist', 'Subject specialist') - }); - unless ( TableExists('erm_licenses') ) { $dbh->do(q{ CREATE TABLE `erm_licenses` ( @@ -156,6 +130,31 @@ return { ('ERM_AGREEMENT_LICENSE_LOCATION', 'cupboard', 'Cupboard'); }); + unless ( TableExists('erm_user_roles') ) { + $dbh->do(q{ + CREATE TABLE `erm_user_roles` ( + `agreement_id` INT(11) NULL COMMENT 'link to the agreement', + `license_id` INT(11) NULL COMMENT 'link to the license', + `user_id` INT(11) NOT NULL COMMENT 'link to the user', + `role` VARCHAR(80) NOT NULL COMMENT 'role of the user', + CONSTRAINT `erm_user_roles_ibfk_1` FOREIGN KEY (`agreement_id`) REFERENCES `erm_agreements` (`agreement_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `erm_user_roles_ibfk_2` FOREIGN KEY (`license_id`) REFERENCES `erm_licenses` (`license_id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `erm_user_roles_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + }); + } + $dbh->do(q{ + INSERT IGNORE INTO authorised_value_categories (category_name, is_system) + VALUES + ('ERM_USER_ROLES', 1) + }); + $dbh->do(q{ + INSERT IGNORE INTO authorised_values (category, authorised_value, lib) + VALUES + ('ERM_USER_ROLES', 'librarian', 'ERM librarian'), + ('ERM_USER_ROLES', 'subject_specialist', 'Subject specialist') + }); + unless ( TableExists('erm_agreement_relationships') ) { $dbh->do(q{ CREATE TABLE `erm_agreement_relationships` ( -- 2.39.5