Class: Gitlab::BackgroundMigration::PopulateMergeRequestAssigneesTable

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/background_migration/populate_merge_request_assignees_table.rb

Overview

This background migration creates records on merge_request_assignees according to the given merge request IDs range. A single INSERT is issued for the given range. This is required for supporting multiple assignees on merge requests.

Instance Method Summary collapse

Instance Method Details

#perform(from_id, to_id) ⇒ Object


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

def perform(from_id, to_id)
  select_sql =
    MergeRequest
      .where(merge_request_assignees_not_exists_clause)
      .where(id: from_id..to_id)
      .where('assignee_id IS NOT NULL')
      .select(:id, :assignee_id)
      .to_sql

  execute("INSERT INTO merge_request_assignees (merge_request_id, user_id) #{select_sql}")
end

#perform_all_sync(batch_size:) ⇒ Object


21
22
23
24
25
26
27
# File 'lib/gitlab/background_migration/populate_merge_request_assignees_table.rb', line 21

def perform_all_sync(batch_size:)
  MergeRequest.each_batch(of: batch_size) do |batch|
    range = batch.pluck('MIN(id)', 'MAX(id)').first

    perform(*range)
  end
end