From: Jonathan Druart Date: Tue, 8 Nov 2022 07:33:38 +0000 (+0100) Subject: Bug 32030: Create erm_user_roles after erm_licenses X-Git-Tag: v22.11.00~288 X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=commitdiff_plain;h=0204f2051872f82fdb8b701808c377d659b2676e;p=srvgit 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 --- 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` (