Bug 18887: Fix DB structure issues
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 24 Jul 2018 12:01:33 +0000 (09:01 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Wed, 3 Oct 2018 17:58:14 +0000 (17:58 +0000)
- Make atomic update idempotent
- Correct COLLAT (atomic update)
- Add index on rule_name (kohastructure.sql)
- Add rule_name to the unique constraint (kohastructure.sql)
- Remove max_holds columns (kohastructure.sql)

Signed-off-by: Lisette Scheer <lisetteslatah@gmail.com>
Signed-off-by: Jesse Maseto <jesse@bywatersolution.com>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
installer/data/mysql/atomicupdate/bug_18887.perl
installer/data/mysql/kohastructure.sql

index 07ee2d3..85da1d2 100644 (file)
@@ -1,22 +1,24 @@
 $DBversion = 'XXX';  # will be replaced by the RM
 if( CheckVersion( $DBversion ) ) {
 
-    $dbh->do(q{
-        CREATE TABLE `circulation_rules` (
-          `id` int(11) NOT NULL auto_increment,
-          `branchcode` varchar(10) NULL default NULL,
-          `categorycode` varchar(10) NULL default NULL,
-          `itemtype` varchar(10) NULL default NULL,
-          `rule_name` varchar(32) NOT NULL,
-          `rule_value` varchar(32) NOT NULL,
-          PRIMARY KEY (`id`),
-          KEY `branchcode` (`branchcode`),
-          KEY `categorycode` (`categorycode`),
-          KEY `itemtype` (`itemtype`),
-          KEY `rule_name` (`rule_name`),
-          UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`)
-        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-    });
+    unless (TableExists('circulation_rules')){
+        $dbh->do(q{
+            CREATE TABLE `circulation_rules` (
+              `id` int(11) NOT NULL auto_increment,
+              `branchcode` varchar(10) NULL default NULL,
+              `categorycode` varchar(10) NULL default NULL,
+              `itemtype` varchar(10) NULL default NULL,
+              `rule_name` varchar(32) NOT NULL,
+              `rule_value` varchar(32) NOT NULL,
+              PRIMARY KEY (`id`),
+              KEY `branchcode` (`branchcode`),
+              KEY `categorycode` (`categorycode`),
+              KEY `itemtype` (`itemtype`),
+              KEY `rule_name` (`rule_name`),
+              UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`)
+            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+        });
+    }
 
     $dbh->do(q{
         INSERT INTO circulation_rules ( branchcode, categorycode, itemtype, rule_name, rule_value )
index c6b8022..e889d14 100644 (file)
@@ -350,7 +350,6 @@ CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rule
   `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode)
   `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch
   `maxonsiteissueqty` int(4) default NULL, -- the maximum number of on-site checkouts this patron category can have at this branch
-  max_holds INT(4) NULL DEFAULT NULL, -- the maximum number of holds a patron may have at a time
   PRIMARY KEY (`categorycode`, `branchcode`),
   CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
     ON DELETE CASCADE ON UPDATE CASCADE,
@@ -367,7 +366,6 @@ CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found und
   `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul
   `maxissueqty` int(4) default NULL,
   `maxonsiteissueqty` int(4) default NULL,
-  max_holds INT(4) NULL DEFAULT NULL, -- the maximum number of holds a patron may have at a time
   PRIMARY KEY (`categorycode`),
   CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
     ON DELETE CASCADE ON UPDATE CASCADE
@@ -4224,8 +4222,9 @@ CREATE TABLE `circulation_rules` (
   KEY `branchcode` (`branchcode`),
   KEY `categorycode` (`categorycode`),
   KEY `itemtype` (`itemtype`),
-  UNIQUE (`branchcode`,`categorycode`,`itemtype`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+  KEY `rule_name` (`rule_name`),
+  UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 
 /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
 /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;