Class: Gitlab::BackgroundMigration::RenameTaskSystemNoteToChecklistItem

Inherits:
BatchedMigrationJob show all
Defined in:
lib/gitlab/background_migration/rename_task_system_note_to_checklist_item.rb

Overview

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`

Constant Summary collapse

REPLACE_REGEX =
'\Amarked\sthe\stask'
TEXT_REPLACEMENT =
'marked the checklist item'

Constants inherited from BatchedMigrationJob

BatchedMigrationJob::DEFAULT_FEATURE_CATEGORY

Constants included from Database::DynamicModelHelpers

Database::DynamicModelHelpers::BATCH_SIZE

Instance Method Summary collapse

Methods inherited from BatchedMigrationJob

#batch_metrics, feature_category, #filter_batch, generic_instance, #initialize, job_arguments, job_arguments_count, operation_name, scope_to

Methods included from Database::DynamicModelHelpers

#define_batchable_model, #each_batch, #each_batch_range

Constructor Details

This class inherits a constructor from Gitlab::BackgroundMigration::BatchedMigrationJob

Instance Method Details

#performObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/background_migration/rename_task_system_note_to_checklist_item.rb', line 19

def perform
  each_sub_batch 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