mirror of
https://github.com/gitlabhq/gitlabhq.git
synced 2025-08-20 16:30:26 +00:00
Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
@ -22,8 +22,8 @@ module Gitlab
|
||||
def next_batch(table_name, column_name, batch_min_value:, batch_size:, job_arguments:, job_class: nil)
|
||||
model_class = define_batchable_model(table_name, connection: connection)
|
||||
|
||||
quoted_column_name = model_class.connection.quote_column_name(column_name)
|
||||
relation = model_class.where("#{quoted_column_name} >= ?", batch_min_value)
|
||||
arel_column = model_class.arel_table[column_name]
|
||||
relation = model_class.where(arel_column.gteq(batch_min_value))
|
||||
|
||||
if job_class
|
||||
relation = filter_batch(relation,
|
||||
@ -36,7 +36,7 @@ module Gitlab
|
||||
next_batch_bounds = nil
|
||||
|
||||
relation.each_batch(of: batch_size, column: column_name) do |batch| # rubocop:disable Lint/UnreachableLoop
|
||||
next_batch_bounds = batch.pick(Arel.sql("MIN(#{quoted_column_name}), MAX(#{quoted_column_name})"))
|
||||
next_batch_bounds = batch.pick(arel_column.minimum, arel_column.maximum)
|
||||
|
||||
break
|
||||
end
|
||||
|
@ -58,10 +58,5 @@ FactoryBot.define do
|
||||
after(:build) do |build, evaluator|
|
||||
build.project = build.pipeline.project
|
||||
end
|
||||
|
||||
factory :generic_commit_status, class: 'GenericCommitStatus' do
|
||||
name { 'generic' }
|
||||
description { 'external commit status' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
8
spec/factories/generic_commit_statuses.rb
Normal file
8
spec/factories/generic_commit_statuses.rb
Normal file
@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
FactoryBot.define do
|
||||
factory :generic_commit_status, class: 'GenericCommitStatus', parent: :commit_status do
|
||||
name { 'generic' }
|
||||
description { 'external commit status' }
|
||||
end
|
||||
end
|
@ -60,6 +60,22 @@ RSpec.describe Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchi
|
||||
|
||||
expect(batch_bounds).to eq([namespace4.id, namespace4.id])
|
||||
end
|
||||
|
||||
context 'when scope has a join which makes the column name ambiguous' do
|
||||
let(:job_class) do
|
||||
Class.new(Gitlab::BackgroundMigration::BatchedMigrationJob) do
|
||||
scope_to ->(r) { r.joins('LEFT JOIN users ON users.id = namespaces.owner_id') }
|
||||
end
|
||||
end
|
||||
|
||||
it 'executes the correct query' do
|
||||
expect(job_class).to receive(:generic_instance).and_call_original
|
||||
|
||||
batch_bounds = batching_strategy.next_batch(:namespaces, :id, batch_min_value: namespace4.id, batch_size: 3, job_arguments: [], job_class: job_class)
|
||||
|
||||
expect(batch_bounds).to eq([namespace4.id, namespace4.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'additional filters' do
|
||||
|
Reference in New Issue
Block a user