summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration/fix_promoted_epics_discussion_ids.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/background_migration/fix_promoted_epics_discussion_ids.rb')
-rw-r--r--lib/gitlab/background_migration/fix_promoted_epics_discussion_ids.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/fix_promoted_epics_discussion_ids.rb b/lib/gitlab/background_migration/fix_promoted_epics_discussion_ids.rb
new file mode 100644
index 00000000000..1a80ccdee92
--- /dev/null
+++ b/lib/gitlab/background_migration/fix_promoted_epics_discussion_ids.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BackgroundMigration
+ # This migration updates discussion ids for epics that were promoted from issue so that the discussion id on epics
+ # is different from discussion id on issue, which was causing problems when replying to epic discussions as it would
+ # identify the discussion as related to an issue and complaint about missing project_id
+ class FixPromotedEpicsDiscussionIds
+ # notes model to iterate through the notes to be updated
+ class Note < ActiveRecord::Base
+ self.table_name = 'notes'
+ self.inheritance_column = :_type_disabled
+ end
+
+ def perform(discussion_ids)
+ Note.where(noteable_type: 'Epic')
+ .where(discussion_id: discussion_ids)
+ .update_all("discussion_id=MD5(discussion_id)||substring(discussion_id from 1 for 8)")
+ end
+ end
+ end
+end