forked from science-ation/science-ation
add the database updater code, and always ensure that the code and db are running the same version
This commit is contained in:
parent
f89b130fd3
commit
81e1559b8d
@ -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 "<html><head><title>SFIAB ERROR</title></head><body>";
|
||||
echo "<h1>Science Fair In A Box - ERROR</h1>";
|
||||
echo "SFIAB database and code are mismatched";
|
||||
echo "<br>";
|
||||
echo "Please run the db_update.php script in order to update";
|
||||
echo "<br>";
|
||||
echo "your database to the same version as the code";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<br>";
|
||||
echo "<h2>Details</h2>";
|
||||
echo "Current SFIAB codebase requires DB version: ".$dbcodeversion[0];
|
||||
echo "<br>";
|
||||
echo "Current SFIAB database is detected as version: ".$dbdbversion[0];
|
||||
echo "<br>";
|
||||
echo "</body></html>";
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once("config.inc.php");
|
||||
require_once("committee_auth.php");
|
||||
mysql_connect($DBHOST,$DBUSER,$DBPASS);
|
||||
|
8
db/FILES
Normal file
8
db/FILES
Normal file
@ -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
|
||||
|
1
db/db.code.version.txt
Normal file
1
db/db.code.version.txt
Normal file
@ -0,0 +1 @@
|
||||
2
|
0
db/db.update.1.sql
Normal file
0
db/db.update.1.sql
Normal file
1
db/db.update.2.sql
Normal file
1
db/db.update.2.sql
Normal file
@ -0,0 +1 @@
|
||||
ALTER TABLE `judges` ADD `complete` ENUM( 'no', 'yes' ) DEFAULT 'no' NOT NULL;
|
71
db/db_update.php
Normal file
71
db/db_update.php
Normal file
@ -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 ($dbcodeversion<$dbdbversion). This should not happen!";
|
||||
|
||||
}
|
||||
else if($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 <db.update.$ver.sql");
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "Version $ver update file not found - skipping over\n";
|
||||
}
|
||||
}
|
||||
$fp=fopen("db.db.version.txt","w");
|
||||
fputs($fp,$dbcodeversion."\n");
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "ERROR: dbcodeversion and dbdbversion are not defined\n";
|
||||
}
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user