From 81e1559b8d5c59177cda86ef8e754e623478f21a Mon Sep 17 00:00:00 2001 From: james Date: Thu, 10 Mar 2005 17:28:15 +0000 Subject: [PATCH] add the database updater code, and always ensure that the code and db are running the same version --- common.inc.php | 24 ++++++++++++++ db/FILES | 8 +++++ db/db.code.version.txt | 1 + db/db.update.1.sql | 0 db/db.update.2.sql | 1 + db/db_update.php | 71 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 105 insertions(+) create mode 100644 db/FILES create mode 100644 db/db.code.version.txt create mode 100644 db/db.update.1.sql create mode 100644 db/db.update.2.sql create mode 100644 db/db_update.php diff --git a/common.inc.php b/common.inc.php index 73c0456..da2b798 100644 --- a/common.inc.php +++ b/common.inc.php @@ -22,6 +22,30 @@ */ ?> SFIAB ERROR"; + echo "

Science Fair In A Box - ERROR

"; + echo "SFIAB database and code are mismatched"; + echo "
"; + echo "Please run the db_update.php script in order to update"; + echo "
"; + echo "your database to the same version as the code"; + echo "
"; + echo "
"; + echo "
"; + echo "

Details

"; + echo "Current SFIAB codebase requires DB version: ".$dbcodeversion[0]; + echo "
"; + echo "Current SFIAB database is detected as version: ".$dbdbversion[0]; + echo "
"; + echo ""; + exit; +} + require_once("config.inc.php"); require_once("committee_auth.php"); mysql_connect($DBHOST,$DBUSER,$DBPASS); diff --git a/db/FILES b/db/FILES new file mode 100644 index 0000000..8584023 --- /dev/null +++ b/db/FILES @@ -0,0 +1,8 @@ +db.code.version.txt - contains the version number of the database that the code requires +db.db.version.txt - contains the actual version number of the database +db_update.php - will update the db to the newest version (db.code=db.db) + +db.update.1.sql - the SQL commands required to update - to upgrade across multiple versions +db.update.2.sql - each file should be executed in sequence from the current version up. +db.update.3.sql - etc + diff --git a/db/db.code.version.txt b/db/db.code.version.txt new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/db/db.code.version.txt @@ -0,0 +1 @@ +2 diff --git a/db/db.update.1.sql b/db/db.update.1.sql new file mode 100644 index 0000000..e69de29 diff --git a/db/db.update.2.sql b/db/db.update.2.sql new file mode 100644 index 0000000..ef78ff0 --- /dev/null +++ b/db/db.update.2.sql @@ -0,0 +1 @@ +ALTER TABLE `judges` ADD `complete` ENUM( 'no', 'yes' ) DEFAULT 'no' NOT NULL; diff --git a/db/db_update.php b/db/db_update.php new file mode 100644 index 0000000..1593299 --- /dev/null +++ b/db/db_update.php @@ -0,0 +1,71 @@ +$dbdbversion) + { + echo "DB update requirements detected\n"; + echo "Current DB Version: $dbdbversion\n"; + echo "Current CODE Version: $dbcodeversion\n"; + echo "Updating database from $dbdbversion to $dbcodeversion\n"; + //include the config.inc.php + //so we have the db connection info + require("../config.inc.php"); + + for($ver=$dbdbversion+1;$ver<=$dbcodeversion;$ver++) + { + if(file_exists("db.update.$ver.sql")) + { + echo "db.update.$ver.sql detected - running...\n"; + system("mysql -h$DBHOST -u$DBUSER -p$DBPASS $DBNAME