Class: Gitlab::BackgroundMigration::CopyColumnUsingBackgroundMigrationJob
- Inherits:
-
BatchedMigrationJob
- Object
- BatchedMigrationJob
- Gitlab::BackgroundMigration::CopyColumnUsingBackgroundMigrationJob
- 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 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, cursor, cursor?, cursor_columns, 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
#perform ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/gitlab/background_migration/copy_column_using_background_migration_job.rb', line 21 def perform assignment_clauses = build_assignment_clauses(copy_from, copy_to) each_sub_batch do |relation| relation.update_all(assignment_clauses) end end |