Class: Gitlab::BackgroundMigration::CopyRunnerTaggings

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

Constant Summary

Constants inherited from BatchedMigrationJob

BatchedMigrationJob::DEFAULT_FEATURE_CATEGORY, BatchedMigrationJob::MINIMUM_PAUSE_MS

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

#performObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/background_migration/copy_runner_taggings.rb', line 9

def perform
  each_sub_batch do |sub_batch|
    scope = sub_batch.where(runner_type: 1).or(sub_batch.where.not(sharding_key_id: nil))
    scope = scope
      .joins('inner join taggings on ci_runners.id = taggings.taggable_id')
      .joins('inner join ci_runners_e59bb2812d on ci_runners.id = ci_runners_e59bb2812d.id')
      .where(taggings: { taggable_type: 'Ci::Runner' })
      .select(:tag_id, 'taggable_id as runner_id', :sharding_key_id, :runner_type)

    connection.execute(<<~SQL.squish)
      INSERT INTO ci_runner_taggings(tag_id, runner_id, sharding_key_id, runner_type)
      (#{scope.to_sql})
      ON CONFLICT DO NOTHING;
    SQL
  end
end