Class: Gitlab::BackgroundMigration::BackfillProjectNamespaceOnIssues

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

Overview

Back-fills the ‘issues.namespace_id` by setting it to corresponding project.project_namespace_id

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



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gitlab/background_migration/backfill_project_namespace_on_issues.rb', line 12

def perform
  each_sub_batch(
    batching_scope: -> (relation) {
      relation.joins("INNER JOIN projects ON projects.id = issues.project_id")
        .select("issues.id AS issue_id, projects.project_namespace_id").where(issues: { namespace_id: nil })
    }
  ) do |sub_batch|
    # updating issues table results in failed batches quite a bit,
    # to prevent that as much as possible we try to update the same sub-batch up to 3 times.
    update_with_retry(sub_batch)
  end
end