Fix migration system
This commit is contained in:
Родитель
294b1f27d7
Коммит
1fbf350b4f
|
@ -34,14 +34,16 @@ if (mysql_num_rows($query) == 1) {
|
|||
mysql_query("INSERT INTO awfy_config (`key`,value) VALUES ('migration', '$version')");
|
||||
}
|
||||
|
||||
function run($version) {
|
||||
include "migration-".$version.".php";
|
||||
$migrate();
|
||||
}
|
||||
while (true) {
|
||||
|
||||
if (!file_exists("migration-".++$version.".php"))
|
||||
break;
|
||||
|
||||
echo "Running migration migration-".$version.".php\n";
|
||||
include "migration-".$version.".php";
|
||||
migrate();
|
||||
run($version);
|
||||
mysql_query("UPDATE awfy_config SET value = '$version' WHERE awfy_config.key = 'migration'");
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
// Demote 'stamp' to a number that will be sequential to base off the sorting.
|
||||
|
||||
function migrate() {
|
||||
$migrate = function() {
|
||||
mysql_query("ALTER TABLE `awfy_run` CHANGE `stamp` `sort_order` INT( 10 ) UNSIGNED NOT NULL ;") or die(mysql_error());
|
||||
}
|
||||
};
|
||||
|
||||
function rollback() {
|
||||
$rollback = function() {
|
||||
mysql_query("ALTER TABLE `awfy_run` CHANGE `sort_order` `stamp` INT( 10 ) UNSIGNED NOT NULL ;") or die(mysql_error());
|
||||
}
|
||||
};
|
||||
|
|
|
@ -10,7 +10,7 @@ $migration = mysql_fetch_object($query);
|
|||
$version = $migration->version;
|
||||
echo "Rolling back migration migration-".$version.".php\n";
|
||||
include "migration-".$version.".php";
|
||||
rollback();
|
||||
$rollback();
|
||||
mysql_query("UPDATE awfy_config SET value = '".($version-1)."' WHERE awfy_config.key = 'migration'");
|
||||
|
||||
echo "Currently at migration: ".($version - 1)."\n";
|
||||
|
|
Загрузка…
Ссылка в новой задаче