From 16d242876c26f27347e8d359908d52fec3f68eff Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 2 Jan 2025 22:02:55 +0100 Subject: [PATCH] Make mig downgrade failsafe --- application/migrations/233_clubstations.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/application/migrations/233_clubstations.php b/application/migrations/233_clubstations.php index 5690d7c39..fe88ac35d 100644 --- a/application/migrations/233_clubstations.php +++ b/application/migrations/233_clubstations.php @@ -40,12 +40,18 @@ class Migration_clubstations extends CI_Migration { $this->db->query("ALTER TABLE `cat` MODIFY operator INT(6) NOT NULL;"); } - public function down() { - // 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 - $this->db->query("ALTER TABLE `users` DROP COLUMN created_at;"); - $this->db->query("ALTER TABLE `users` DROP COLUMN modified_at;"); - $this->db->query("ALTER TABLE `api` DROP COLUMN created_at;"); + public function down() { + // 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 + if ($this->db->field_exists('created_at', 'users')) { + $this->db->query("ALTER TABLE `users` 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) { @@ -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."); } } -} \ No newline at end of file +}