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

rename_task_system_note_to_checklist_item.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 718fb0aaa71d654147e2720d53c3719b5ed062aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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