Class: Gitlab::BackgroundMigration::BackfillWorkItemTypeIdForIssues

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

Overview

Backfills the ‘issues.work_item_type_id` column, replacing any instances of `NULL` with the appropriate `work_item_types.id` based on `issues.issue_type`

Defined Under Namespace

Classes: MigrationIssue

Constant Summary collapse

MAX_UPDATE_RETRIES =
3

Constants inherited from BatchedMigrationJob

Gitlab::BackgroundMigration::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



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gitlab/background_migration/backfill_work_item_type_id_for_issues.rb', line 26

def perform
  each_sub_batch do |sub_batch|
    first, last = sub_batch.pick(Arel.sql('min(id), max(id)'))

    # The query need to be reconstructed because .each_batch modifies the default scope
    # See: https://gitlab.com/gitlab-org/gitlab/-/issues/330510
    reconstructed_sub_batch = MigrationIssue.unscoped.base_query(base_type).where(id: first..last)

    update_with_retry(reconstructed_sub_batch, base_type_id)
  end
end