Class: Gitlab::Database::Batch::Strategies::PrimaryKey

Inherits:
BaseStrategy
  • Object
show all
Includes:
DynamicModelHelpers
Defined in:
lib/gitlab/database/batch/strategies/primary_key.rb

Overview

Batches over the given table and column combination, returning the MIN() and MAX() values for the next batch as an array of array (compatible with composite PK)

If no more batches exist in the table, returns nil.

Constant Summary

Constants included from DynamicModelHelpers

DynamicModelHelpers::BATCH_SIZE

Instance Method Summary collapse

Methods included from DynamicModelHelpers

define_batchable_model, #each_batch, #each_batch_range

Methods inherited from BaseStrategy

#initialize

Constructor Details

This class inherits a constructor from Gitlab::Database::Batch::Strategies::BaseStrategy

Instance Method Details

#next_batch(table_name, batch_min_value:, batch_size:, job_class: nil) ⇒ Object

Finds and returns the next batch in the table.

table_name - The table to batch over batch_min_value - The minimum value which the next batch will start at batch_size - The size of the next batch job_class - The migration job class



20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/database/batch/strategies/primary_key.rb', line 20

def next_batch(table_name, batch_min_value:, batch_size:, job_class: nil)
  base_class = Gitlab::Database.application_record_for_connection(connection)
  model_class = define_batchable_model(table_name, connection: connection, base_class: base_class)

  cursor_columns = job_class.cursor_columns
  iterator = create_keyset_iterator(model_class, cursor_columns, batch_min_value)

  extract_batch_bounds(iterator, batch_size, cursor_columns)
end