Bug 8835: New db rev for issn_idx
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Thu, 13 Oct 2016 08:49:17 +0000 (10:49 +0200)
committerKyle M Hall <kyle@bywatersolutions.com>
Tue, 22 Nov 2016 17:45:29 +0000 (17:45 +0000)
This db rev reapplies dbrev 3.15.00.049 in case that one failed due to
existence of issn_idx.

Test plan:
If you do not have index issn_idx, recreate it:
    ALTER TABLE biblioitems ADD INDEX issn_idx (issn (255))
Run this db rev. You should see: Removed issn_idx.
Rerun the dbrev. You should see: Everything is fine.

Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
installer/data/mysql/atomicupdate/8835_dbrev.perl [new file with mode: 0644]

diff --git a/installer/data/mysql/atomicupdate/8835_dbrev.perl b/installer/data/mysql/atomicupdate/8835_dbrev.perl
new file mode 100644 (file)
index 0000000..eee4e75
--- /dev/null
@@ -0,0 +1,23 @@
+$DBversion = "16.06.00.XXX";
+if ( CheckVersion($DBversion) ) {
+
+    # If index issn_idx still exists, we assume that dbrev 3.15.00.049 failed,
+    # and we repeat it (partially).
+    # Note: the db rev only pertains to biblioitems and is not needed for
+    # deletedbiblioitems.
+
+    my $temp = $dbh->selectall_arrayref( "SHOW INDEXES FROM biblioitems WHERE key_name = 'issn_idx'" );
+
+    if( @$temp > 0 ) {
+        $dbh->do( "ALTER TABLE biblioitems DROP INDEX isbn" );
+        $dbh->do( "ALTER TABLE biblioitems DROP INDEX issn" );
+        $dbh->do( "ALTER TABLE biblioitems DROP INDEX issn_idx" );
+        $dbh->do( "ALTER TABLE biblioitems CHANGE isbn isbn MEDIUMTEXT NULL DEFAULT NULL, CHANGE issn issn MEDIUMTEXT NULL DEFAULT NULL" );
+        $dbh->do( "ALTER TABLE biblioitems ADD INDEX isbn ( isbn ( 255 ) ), ADD INDEX issn ( issn ( 255 ) )" );
+        print "Upgrade to $DBversion done (Bug 8835). Removed issn_idx.\n";
+    } else {
+        print "Upgrade to $DBversion done (Bug 8835). Everything is fine.\n";
+    }
+
+    SetVersion($DBversion);
+}