BUGFIX: fixed missing include in update_db.php
[e-DoKo.git] / update_db.php
index deae974c9f9343309bd0cd7d2145da8b48e3353a..1efac63a9665b2aef502504f619b45ffb765f202 100644 (file)
@@ -22,13 +22,15 @@ error_reporting(E_ALL);
 
 include_once("config.php");                /* needs to be first in list, since other includes use this */
 include_once("./include/db.php");          /* database only */
+include_once("./include/output.php");   /* the rest */
 include_once("./include/functions.php");   /* the rest */
 
 /* make sure that user has set all variables in config.php */
 config_check();
 
 /* open the database */
-if(DB_open()<0)
+$return = DB_open();
+if($return<0 && $return != -2) /* -2 = wrong DB version is ok */
   exit();
 
 /* only callable via cron or CLI */
@@ -36,7 +38,7 @@ if(isset($_SERVER['REMOTE_ADDR']))
   exit();
 
 $old_version = DB_get_version();
-$current_version = 1;
+$current_version = 3;
 
 if($old_version < $current_version)
   echo "Will upgrade your database now:\n";
@@ -56,6 +58,23 @@ switch($old_version)
             " index (email))");
     DB_query("UPDATE Version set version=1");
     echo "Upgraded to version 1.\n";
+  case 1:
+    /* add new rules */
+    DB_query("ALTER TABLE Rulesets".
+            " ADD COLUMN `lowtrump` enum('poverty','cancel','none') default 'poverty' AFTER schweinchen");
+    DB_query("ALTER TABLE Hand".
+            " MODIFY COLUMN `sickness` enum('wedding','nines','poverty','solo','lowtrump') default NULL");
+    DB_query("ALTER TABLE Game".
+            " MODIFY COLUMN `status` enum('pre','play','gameover','cancel-timedout','cancel-nines','cancel-trump','cancel-noplay','cancel-lowtrump') default NULL");
+
+    DB_query("UPDATE Version set version=2");
+    echo "Upgraded to version 2.\n";
+  case 2:
+    DB_query("ALTER TABLE Comment".
+            " ADD COLUMN `game_id` int(11) default NULL AFTER play_id");
+    DB_query("UPDATE Version set version=3");
+    echo "Upgraded to version 3.\n";
+
   }
 
 ?>
\ No newline at end of file