allow failed upgrades

This commit is contained in:
Shish 2012-02-14 06:33:59 +00:00
parent b1c7c79b2c
commit 85fb34e20f

View file

@ -25,18 +25,21 @@ class Upgrade extends Extension {
// now done again as v9 with PDO // now done again as v9 with PDO
if($config->get_int("db_version") < 8) { if($config->get_int("db_version") < 8) {
// if this fails, don't try again
$config->set_bool("in_upgrade", true); $config->set_bool("in_upgrade", true);
$config->set_int("db_version", 8); $config->set_int("db_version", 8);
$database->execute($database->engine->scoreql_to_sql( $database->execute($database->engine->scoreql_to_sql(
"ALTER TABLE images ADD COLUMN locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N" "ALTER TABLE images ADD COLUMN locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N"
)); ));
log_info("upgrade", "Database at version 8"); log_info("upgrade", "Database at version 8");
$config->set_bool("in_upgrade", false); $config->set_bool("in_upgrade", false);
} }
if($config->get_int("db_version") < 9) { if($config->get_int("db_version") < 9) {
$config->set_bool("in_upgrade", true); $config->set_bool("in_upgrade", true);
$config->set_int("db_version", 9);
if($database->db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { if($database->db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
$tables = $database->get_col("SHOW TABLES"); $tables = $database->get_col("SHOW TABLES");
foreach($tables as $table) { foreach($tables as $table) {
@ -44,18 +47,18 @@ class Upgrade extends Extension {
$database->execute("ALTER TABLE $table TYPE=INNODB"); $database->execute("ALTER TABLE $table TYPE=INNODB");
} }
} }
$config->set_int("db_version", 9);
log_info("upgrade", "Database at version 9"); log_info("upgrade", "Database at version 9");
$config->set_bool("in_upgrade", false); $config->set_bool("in_upgrade", false);
} }
if($config->get_int("db_version") < 10) { if($config->get_int("db_version") < 10) {
$config->set_bool("in_upgrade", true); $config->set_bool("in_upgrade", true);
$config->set_int("db_version", 10);
log_info("upgrade", "Adding foreign keys to images"); log_info("upgrade", "Adding foreign keys to images");
$database->Execute("ALTER TABLE images ADD CONSTRAINT foreign_images_owner_id FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT"); $database->Execute("ALTER TABLE images ADD CONSTRAINT foreign_images_owner_id FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT");
$config->set_int("db_version", 10);
log_info("upgrade", "Database at version 10"); log_info("upgrade", "Database at version 10");
$config->set_bool("in_upgrade", false); $config->set_bool("in_upgrade", false);
} }