From 0e0f3e49460611c74184ee48d3b66762c55ac181 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 13 Apr 2017 13:34:36 +0200 Subject: [PATCH] Bug 18427: Add a primary key to serialitems We drop the unique index serialitemsidx and add a primary key consisting of itemnumber just as the unique key did. Test plan: Run the db revision. Apply bug 18182. The TestBuilder.t should no longer fail on serialitems. Signed-off-by: Marcel de Rooy Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- installer/data/mysql/atomicupdate/bug18427.perl | 17 +++++++++++++++++ installer/data/mysql/kohastructure.sql | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug18427.perl diff --git a/installer/data/mysql/atomicupdate/bug18427.perl b/installer/data/mysql/atomicupdate/bug18427.perl new file mode 100644 index 0000000000..a77a9486d2 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug18427.perl @@ -0,0 +1,17 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + + # In order to be overcomplete, we check if the situation is what we expect + if( !index_exists( 'serialitems', 'PRIMARY' ) ) { + if( index_exists( 'serialitems', 'serialitemsidx' ) ) { + $dbh->do(q| +ALTER TABLE serialitems ADD PRIMARY KEY (itemnumber), DROP INDEX serialitemsidx; + |); + } else { + $dbh->do(q|ALTER TABLE serialitems ADD PRIMARY KEY (itemnumber)|); + } + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 18427 - Add a primary key to serialitems)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 261fb37650..857de55f2e 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2441,7 +2441,7 @@ DROP TABLE IF EXISTS `serialitems`; CREATE TABLE `serialitems` ( `itemnumber` int(11) NOT NULL, `serialid` int(11) NOT NULL, - UNIQUE KEY `serialitemsidx` (`itemnumber`), + PRIMARY KEY (`itemnumber`), KEY `serialitems_sfk_1` (`serialid`), CONSTRAINT `serialitems_sfk_1` FOREIGN KEY (`serialid`) REFERENCES `serial` (`serialid`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `serialitems_sfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE -- 2.20.1