Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/background_migration/rename_task_system_note_to_checklist_item.rb')
-rw-r--r--lib/gitlab/background_migration/rename_task_system_note_to_checklist_item.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item.rb b/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item.rb
new file mode 100644
index 00000000000..718fb0aaa71
--- /dev/null
+++ b/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BackgroundMigration
+ # Renames all system notes created when an issuable task is checked/unchecked
+ # from `task` into `checklist item`
+ # `marked the task **Task 1** as incomplete` => `marked the checklist item **Task 1** as incomplete`
+ class RenameTaskSystemNoteToChecklistItem < BatchedMigrationJob
+ REPLACE_REGEX = '\Amarked\sthe\stask'
+ TEXT_REPLACEMENT = 'marked the checklist item'
+
+ scope_to ->(relation) {
+ relation.where(system_note_metadata: { action: :task })
+ }
+
+ def perform
+ each_sub_batch(operation_name: :update_all) do |sub_batch|
+ ApplicationRecord.connection.execute <<~SQL
+ UPDATE notes
+ SET note = REGEXP_REPLACE(notes.note,'#{REPLACE_REGEX}', '#{TEXT_REPLACEMENT}')
+ FROM (#{sub_batch.select(:note_id).to_sql}) AS metadata_fields(note_id)
+ WHERE notes.id = note_id
+ SQL
+ end
+ end
+ end
+ end
+end