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 @@
*/
?>
+//first things first - make sure our DB version matches our CODE version
+$dbcodeversion=@file("db/db.code.version.txt");
+$dbdbversion=@file("db/db.db.version.txt");
+if($dbcodeversion[0]!=$dbdbversion[0])
+{
+ echo "
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 @@
+
+if(file_exists("db.code.version.txt"))
+{
+ $dbcodeversion_file=file("db.code.version.txt");
+ $dbcodeversion=trim($dbcodeversion_file[0]);
+}
+else
+{
+ echo "Couldnt load current db.code.version.txt\n";
+ exit;
+}
+
+if(file_exists("db.db.version.txt"))
+{
+ $dbdbversion_file=file("db.db.version.txt");
+ $dbdbversion=trim($dbdbversion_file[0]);
+}
+else
+{
+ echo "Couldnt load current db.db.version.txt - assuming version is 1\n";
+ $dbdbversion=1;
+}
+
+if($dbcodeversion && $dbdbversion)
+{
+ //lets see if they match
+ if($dbcodeversion == $dbdbversion)
+ {
+ echo "DB and CODE are all up-to-date. Version: $dbdbversion\n";
+ exit;
+ }
+ else if($dbcodeversion<$dbdbversion)
+ {
+ echo "ERROR: dbcodeversion$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