From 985eaba25c80d118744bfad01b4b37078f52b214 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Fri, 12 Apr 2019 19:46:38 +0200 Subject: [PATCH] Bug 14957: Put database updates in perl script Also add schema changes to kohastructure.sql and syspref to sysprefs.sql --- .../bug_14957-marc-merge-rules-permissions.sql | 2 - .../atomicupdate/bug_14957-marc-merge-rules.perl | 56 ++++++++++++++++++++++ .../atomicupdate/bug_14957-marc-merge-rules.sql | 30 ------------ .../atomicupdate/bug_14957-merge-rules-syspref.sql | 1 - 4 files changed, 56 insertions(+), 33 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules-permissions.sql create mode 100644 installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules.perl delete mode 100644 installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules.sql delete mode 100644 installer/data/mysql/atomicupdate/bug_14957-merge-rules-syspref.sql diff --git a/installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules-permissions.sql b/installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules-permissions.sql deleted file mode 100644 index 87739b558b..0000000000 --- a/installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules-permissions.sql +++ /dev/null @@ -1,2 +0,0 @@ -INSERT INTO permissions (module_bit, code, description) VALUES - ( 3, 'manage_marc_merge_rules', 'Manage MARC merge rules configuration'); diff --git a/installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules.perl b/installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules.perl new file mode 100644 index 0000000000..535f619c20 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules.perl @@ -0,0 +1,56 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + my $sql = q{ + CREATE TABLE IF NOT EXISTS `marc_merge_rules_modules` ( + `name` varchar(127) NOT NULL, + `description` varchar(255), + `specificity` int(11) NOT NULL UNIQUE, + PRIMARY KEY(`name`) + ); + }; + $dbh->do( $sql ); + + $dbh->do( "INSERT IGNORE INTO `marc_merge_rules_modules` VALUES('source', 'source from where modification request was sent', 0);" ); + $dbh->do( "INSERT IGNORE INTO `marc_merge_rules_modules` VALUES('category', 'categorycode of user who requested modification', 1);" ); + $dbh->do( "INSERT IGNORE INTO `marc_merge_rules_modules` VALUES('borrower', 'borrowernumber of user who requested modification', 2);" ); + + $sql = q{ + CREATE TABLE IF NOT EXISTS `marc_merge_rules` ( + `id` int(11) NOT NULL auto_increment, + `tag` varchar(255) NOT NULL, -- can be regexp, so need > 3 chars + `module` varchar(127) NOT NULL, + `filter` varchar(255) NOT NULL, + `add` tinyint NOT NULL, + `append` tinyint NOT NULL, + `remove` tinyint NOT NULL, + `delete` tinyint NOT NULL, + PRIMARY KEY(`id`), + CONSTRAINT `marc_merge_rules_ibfk1` FOREIGN KEY (`module`) REFERENCES `marc_merge_rules_modules` (`name`) ON DELETE CASCADE ON UPDATE CASCADE + ); + }; + $dbh->do( $sql ); + + $sql = q{ + INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ( + 'MARCMergeRules', + '0', + NULL, + 'Use the MARC merge rules system to decide what actions to take for each field when modifying records.', + 'YesNo' + ); + }; + $dbh->do( $sql ); + + $sql = q{ + INSERT IGNORE INTO permissions (module_bit, code, description) VALUES ( + 3, + 'manage_marc_merge_rules', + 'Manage MARC merge rules configuration' + ); + }; + $dbh->do( $sql ); + + # Always end with this (adjust the bug info) + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 14957 - Write protecting MARC fields based on source of import)\n"; +} diff --git a/installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules.sql b/installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules.sql deleted file mode 100644 index 67554d7599..0000000000 --- a/installer/data/mysql/atomicupdate/bug_14957-marc-merge-rules.sql +++ /dev/null @@ -1,30 +0,0 @@ -DROP TABLE IF EXISTS `marc_merge_rules`; -DROP TABLE IF EXISTS `marc_merge_rules_modules`; - -CREATE TABLE `marc_merge_rules_modules` ( - `name` varchar(127) NOT NULL, - `description` varchar(255), - `specificity` int(11) NOT NULL UNIQUE, -- higher specificity will override rules with lower specificity - PRIMARY KEY(`name`) -); - --- a couple of useful default filter modules --- these are used in various scripts, so don't remove them if you don't know --- what you're doing. --- New filter modules can be added here when needed -INSERT INTO `marc_merge_rules_modules` VALUES('source', 'source from where modification request was sent', 0); -INSERT INTO `marc_merge_rules_modules` VALUES('category', 'categorycode of user who requested modification', 1); -INSERT INTO `marc_merge_rules_modules` VALUES('borrower', 'borrowernumber of user who requested modification', 2); - -CREATE TABLE IF NOT EXISTS `marc_merge_rules` ( - `id` int(11) NOT NULL auto_increment, - `tag` varchar(255) NOT NULL, -- can be regexp, so need > 3 chars - `module` varchar(127) NOT NULL, - `filter` varchar(255) NOT NULL, - `add` tinyint NOT NULL, - `append` tinyint NOT NULL, - `remove` tinyint NOT NULL, - `delete` tinyint NOT NULL, - PRIMARY KEY(`id`), - CONSTRAINT `marc_merge_rules_ibfk1` FOREIGN KEY (`module`) REFERENCES `marc_merge_rules_modules` (`name`) ON DELETE CASCADE -); diff --git a/installer/data/mysql/atomicupdate/bug_14957-merge-rules-syspref.sql b/installer/data/mysql/atomicupdate/bug_14957-merge-rules-syspref.sql deleted file mode 100644 index 5116c0a355..0000000000 --- a/installer/data/mysql/atomicupdate/bug_14957-merge-rules-syspref.sql +++ /dev/null @@ -1 +0,0 @@ -INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ('MARCMergeRules','0','','Use the MARC merge rules system to decide what actions to take for each field when modifying records.','YesNo'); -- 2.11.0