Class: Gitlab::BackgroundMigration::CopyColumnUsingBackgroundMigrationJob

Inherits:
BatchedMigrationJob
  • Object
show all
Defined in:
lib/gitlab/background_migration/copy_column_using_background_migration_job.rb

Overview

Background migration that updates the value of one or more columns using the value of other columns in the same table.

  • The end_id arguments are at the start so that it can be used with `queue_batched_background_migration`

  • Uses sub-batching so that we can keep each update's execution time at low 100s ms, while being able to update more records per 2 minutes that we allow background migration jobs to be scheduled one after the other

  • We skip the NULL checks as they may result in not using an index scan

  • The table that is migrated does not need `id` as the primary key We use the provided primary_key column to perform the update.

Constant Summary

Constants included from Database::DynamicModelHelpers

Database::DynamicModelHelpers::BATCH_SIZE

Instance Method Summary collapse

Methods inherited from BatchedMigrationJob

#batch_metrics, #initialize

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

#perform(copy_from, copy_to) ⇒ Object


17
18
19
20
21
22
23
# File 'lib/gitlab/background_migration/copy_column_using_background_migration_job.rb', line 17

def perform(copy_from, copy_to)
  assignment_clauses = build_assignment_clauses(copy_from, copy_to)

  each_sub_batch(operation_name: :update_all) do |relation|
    relation.update_all(assignment_clauses)
  end
end