From a4a60be9c7e810d1e0d2ce0b7d4c8bba6ac89afc Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms Date: Fri, 27 Feb 2026 15:59:30 +0100 Subject: fix migration mess, fixes #6255 Closes #6255 Merge request studip/studip!4729 --- ...nique_constraint_to_forum_posting_reactions.php | 47 ++++++++++++++++++++++ ...nique_constraint_to_forum_posting_reactions.php | 30 ++++---------- 2 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 db/migrations/6.1.19_add_unique_constraint_to_forum_posting_reactions.php diff --git a/db/migrations/6.1.19_add_unique_constraint_to_forum_posting_reactions.php b/db/migrations/6.1.19_add_unique_constraint_to_forum_posting_reactions.php new file mode 100644 index 0000000..37c947a --- /dev/null +++ b/db/migrations/6.1.19_add_unique_constraint_to_forum_posting_reactions.php @@ -0,0 +1,47 @@ +exec(" + DELETE t1 + FROM forum_posting_reactions AS t1 + JOIN forum_posting_reactions AS t2 + ON t1.posting_id = t2.posting_id + AND t1.user_id = t2.user_id + AND t1.emoji = t2.emoji + AND t1.id > t2.id; + "); + + // Migration was once defined as 6.2.2 thus we need to check if the + // constraint already exists and cleanup table schema_version. + + if (!$this->hasConstraint()) { + DBManager::get()->exec( + "ALTER TABLE forum_posting_reactions ADD CONSTRAINT unique_posting_user_emoji UNIQUE (posting_id, user_id, emoji)" + ); + } + + if (!file_exists(__DIR__ . '/6.2.1_add_booking_text_to_resource_requests.php')) { + $query = "DELETE FROM schema_version + WHERE `domain` = 'studip' + AND `branch` = '6.2' + AND `version` = '2';"; + DBManager::get()->exec($query); + } + } + + protected function down() + { + DBManager::get()->exec("ALTER TABLE forum_posting_reactions DROP INDEX unique_posting_user_emoji"); + } + + private function hasConstraint(): bool + { + $query = "SHOW INDEX + FROM forum_posting_reactions + WHERE Key_name = 'unique_posting_user_emoji'"; + return (bool) DBManager::get()->fetchColumn($query); + } +} diff --git a/db/migrations/6.2.2_add_unique_constraint_to_forum_posting_reactions.php b/db/migrations/6.2.2_add_unique_constraint_to_forum_posting_reactions.php index 4a73a9f..f867abd 100644 --- a/db/migrations/6.2.2_add_unique_constraint_to_forum_posting_reactions.php +++ b/db/migrations/6.2.2_add_unique_constraint_to_forum_posting_reactions.php @@ -1,27 +1,11 @@ exec(" - DELETE t1 - FROM forum_posting_reactions AS t1 - JOIN forum_posting_reactions AS t2 - ON t1.posting_id = t2.posting_id - AND t1.user_id = t2.user_id - AND t1.emoji = t2.emoji - AND t1.id > t2.id; - "); - - DBManager::get()->exec( - "ALTER TABLE forum_posting_reactions ADD CONSTRAINT unique_posting_user_emoji UNIQUE (posting_id, user_id, emoji)" - ); + return 'Dummy migration that does nothing'; } - - protected function down() - { - DBManager::get()->exec("ALTER TABLE forum_posting_reactions DROP INDEX unique_posting_user_emoji"); - } -} +}; -- cgit v1.0