Class: Gitlab::BackgroundMigration::BackfillProjectMemberNamespaceId

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

Overview

Backfills the ‘members.member_namespace_id` column for `type=ProjectMember`

Constant Summary

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

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

#batch_metricsObject



24
25
26
# File 'lib/gitlab/background_migration/backfill_project_member_namespace_id.rb', line 24

def batch_metrics
  @batch_metrics ||= Gitlab::Database::BackgroundMigration::BatchMetrics.new
end

#performObject



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

def perform
  parent_batch_relation = relation_scoped_to_range(batch_table, batch_column, start_id, end_id)

  parent_batch_relation.each_batch(column: batch_column, of: sub_batch_size, order_hint: :type) do |sub_batch|
    batch_metrics.time_operation(:update_all) do
      # rubocop:disable Layout/LineLength
      sub_batch.update_all('member_namespace_id = (SELECT projects.project_namespace_id FROM projects WHERE projects.id = source_id)')
      # rubocop:enable Layout/LineLength
    end

    pause_ms_value = [0, pause_ms].max
    sleep(pause_ms_value * 0.001)
  end
end