mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
Make mig downgrade failsafe
This commit is contained in:
@@ -40,12 +40,18 @@ class Migration_clubstations extends CI_Migration {
|
|||||||
$this->db->query("ALTER TABLE `cat` MODIFY operator INT(6) NOT NULL;");
|
$this->db->query("ALTER TABLE `cat` MODIFY operator INT(6) NOT NULL;");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function down() {
|
public function down() {
|
||||||
// Due the risk of data loss we can't drop any new created columns or tables
|
// Due the risk of data loss we can't drop any new created columns or tables
|
||||||
// But we can drop some of the timestamp columns
|
// But we can drop some of the timestamp columns
|
||||||
$this->db->query("ALTER TABLE `users` DROP COLUMN created_at;");
|
if ($this->db->field_exists('created_at', 'users')) {
|
||||||
$this->db->query("ALTER TABLE `users` DROP COLUMN modified_at;");
|
$this->db->query("ALTER TABLE `users` DROP COLUMN created_at;");
|
||||||
$this->db->query("ALTER TABLE `api` DROP COLUMN created_at;");
|
}
|
||||||
|
if ($this->db->field_exists('modified_at', 'users')) {
|
||||||
|
$this->db->query("ALTER TABLE `users` DROP COLUMN modified_at;");
|
||||||
|
}
|
||||||
|
if ($this->db->field_exists('created_at', 'api')) {
|
||||||
|
$this->db->query("ALTER TABLE `api` DROP COLUMN created_at;");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function add_column_if_not_exists($table, $column, $definition) {
|
private function add_column_if_not_exists($table, $column, $definition) {
|
||||||
@@ -61,4 +67,4 @@ class Migration_clubstations extends CI_Migration {
|
|||||||
log_message('info', "Mig 230 - Column '$column' already exists in table '$table', skipping ALTER TABLE.");
|
log_message('info', "Mig 230 - Column '$column' already exists in table '$table', skipping ALTER TABLE.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user