Bug 14187: (QA followup) Properly check DB structure before altering it
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 12 Jan 2017 15:42:05 +0000 (12:42 -0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 13 Jan 2017 12:20:12 +0000 (12:20 +0000)
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
installer/data/mysql/atomicupdate/14187.perl

index 02022b4..5a7fa67 100644 (file)
@@ -1,8 +1,15 @@
-$DBversion = 'XXX';  # will be replaced by the RM
-if( CheckVersion( $DBversion )  ) {
-    $dbh->do("ALTER TABLE branchtransfers ADD COLUMN branchtransfer_id int(12) NOT NULL auto_increment FIRST, ADD CONSTRAINT PRIMARY KEY (branchtransfer_id);");
+$DBversion = '16.12.00.XXX';
+if ( CheckVersion($DBversion) ) {
+    unless (column_exists( 'branchtransfers', 'branchtransfer_id' )
+        and index_exists( 'branchtransfers', 'PRIMARY' ) )
+    {
+        $dbh->do(
+            "ALTER TABLE branchtransfers
+                 ADD COLUMN branchtransfer_id int(12) NOT NULL auto_increment FIRST, ADD CONSTRAINT PRIMARY KEY (branchtransfer_id);"
+        );
+    }
 
     # Always end with this (adjust the bug info)
-    SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 14187 - branchtransfer needs a primary key (id) for DBIx and common sense.)\n";
+    SetVersion($DBversion);
+    print "Upgrade to $DBversion done (Bug 14187: branchtransfer needs a primary key (id) for DBIx and common sense.)\n";
 }