diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2026-02-27 15:59:30 +0100 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2026-02-27 15:59:30 +0100 |
| commit | a4a60be9c7e810d1e0d2ce0b7d4c8bba6ac89afc (patch) | |
| tree | a4ce9a37130cdec1fc81223b49dbe1dde012c069 /db | |
| parent | 7dd8f9c17febec764d515e0e9e151ae3d6736e19 (diff) | |
fix migration mess, fixes #6255
Closes #6255
Merge request studip/studip!4729
Diffstat (limited to 'db')
| -rw-r--r-- | db/migrations/6.1.19_add_unique_constraint_to_forum_posting_reactions.php | 47 | ||||
| -rw-r--r-- | db/migrations/6.2.2_add_unique_constraint_to_forum_posting_reactions.php | 30 |
2 files changed, 54 insertions, 23 deletions
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 @@ +<?php +final class AddUniqueConstraintToForumPostingReactions extends Migration +{ + protected function up() + { + // remove duplicate reactions + DBManager::get()->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 @@ <?php - -final class AddUniqueConstraintToForumPostingReactions extends Migration +/** + * @see https://gitlab.studip.de/studip/studip/-/issues/6255 + */ +return new class extends Migration { - protected function up() + public function description() { - // remove duplicate reactions - DBManager::get()->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"); - } -} +}; |
