From 86a0f5fdad48719ccf3b2b48e2ff2c69f9c6a851 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Wed, 11 May 2022 10:14:52 +0000 Subject: [PATCH] add migration that removes column termine.topic_id, fixes #881 Closes #881 Merge request studip/studip!519 --- ...0220524_remove_column_termine_topic_id.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 db/migrations/20220524_remove_column_termine_topic_id.php diff --git a/db/migrations/20220524_remove_column_termine_topic_id.php b/db/migrations/20220524_remove_column_termine_topic_id.php new file mode 100644 index 00000000000..992e765e2d8 --- /dev/null +++ b/db/migrations/20220524_remove_column_termine_topic_id.php @@ -0,0 +1,41 @@ +<?php +/** + * @see https://gitlab.studip.de/studip/studip/-/issues/881 + */ +final class RemoveColumnTermineTopicId extends Migration +{ + public function description() + { + return 'Removes unused column topic_id from table termine.'; + } + + protected function up() + { + if (!$this->columnExists('termine', 'topic_id')) { + $this->write("Column termine.topic_id does not exist"); + return; + } + + $query = "ALTER TABLE `termine` + DROP COLUMN `topic_id`"; + DBManager::get()->exec($query); + } + + protected function down() + { + if ($this->columnExists('termine', 'topic_id')) { + $this->write("Column termine.topic_id already exists"); + return; + } + + $query = "ALTER TABLE `termine` + ADD COLUMN `topic_id` VARCHAR(32) COLLATE latin1_bin DEFAULT NULL"; + DBManager::get()->exec($query); + } + + protected function columnExists(string $table, string $column): bool + { + $query = "SHOW COLUMNS FROM `{$table}` LIKE ?"; + return (bool) DBManager::get()->fetchOne($query, [$column]); + } +} -- GitLab