From e9e965f27f7f140e3a6e7e5f6cc383bca466fe63 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Tue, 31 Mar 2020 16:24:53 +0000 Subject: [PATCH] Bug 26814: Add a new column onsite_checkout to circulation_rules table To add: 1. perl installer/data/mysql/updatedatabase.pl Sponsored-by: The National Library of Finland --- ...dd_checkout_type_to_circulation_rules.perl | 21 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug_26814_1_add_checkout_type_to_circulation_rules.perl diff --git a/installer/data/mysql/atomicupdate/bug_26814_1_add_checkout_type_to_circulation_rules.perl b/installer/data/mysql/atomicupdate/bug_26814_1_add_checkout_type_to_circulation_rules.perl new file mode 100644 index 0000000000..b7e3225ea3 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_26814_1_add_checkout_type_to_circulation_rules.perl @@ -0,0 +1,21 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + + if ( ! column_exists( 'circulation_rules', 'onsite_checkout' ) ) { + $dbh->do( q| + ALTER TABLE circulation_rules ADD COLUMN onsite_checkout INT(1) DEFAULT NULL AFTER branchcode; + | ); + + if ( index_exists( 'circulation_rules', 'branchcode' ) ) { + # we need to drop this forgein key before updating our unique index + $dbh->do( "ALTER TABLE `circulation_rules` DROP FOREIGN KEY circ_rules_ibfk_1;" ); + $dbh->do( "ALTER TABLE `circulation_rules` DROP INDEX `branchcode`;" ); # index columns: branchcode, categorycode, itemtype and rule_name + $dbh->do( "ALTER TABLE `circulation_rules` ADD CONSTRAINT circ_rules_ibfk_1 FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE" ); + $dbh->do( "ALTER TABLE `circulation_rules` ADD UNIQUE INDEX (`branchcode`,`onsite_checkout`,`categorycode`,`itemtype`,`rule_name`)" ); + } + } + + # Always end with this (adjust the bug info) + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 26814 - Add new circulation rule scope onsite_checkout )\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index fc9953bb2b..ff8e5afe77 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4430,6 +4430,7 @@ DROP TABLE IF EXISTS `circulation_rules`; CREATE TABLE `circulation_rules` ( `id` int(11) NOT NULL auto_increment, `branchcode` varchar(10) NULL default NULL, + `onsite_checkout` int(1) NULL default NULL, `categorycode` varchar(10) NULL default NULL, `itemtype` varchar(10) NULL default NULL, `rule_name` varchar(32) NOT NULL, @@ -4439,7 +4440,7 @@ CREATE TABLE `circulation_rules` ( CONSTRAINT `circ_rules_ibfk_2` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `circ_rules_ibfk_3` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE, KEY `rule_name` (`rule_name`), - UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`) + UNIQUE (`branchcode`,`onsite_checkout`,`categorycode`,`itemtype`,`rule_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- 2.17.1