Make sure all stages are migrated after a cleanup
This commit is contained in:
parent
9106975d3c
commit
73d31251af
2 changed files with 27 additions and 0 deletions
|
@ -5,8 +5,19 @@ class CleanStagesStatusesMigration < ActiveRecord::Migration
|
|||
|
||||
disable_ddl_transaction!
|
||||
|
||||
class Stage < ActiveRecord::Base
|
||||
include ::EachBatch
|
||||
self.table_name = 'ci_stages'
|
||||
end
|
||||
|
||||
def up
|
||||
Gitlab::BackgroundMigration.steal('MigrateStageStatus')
|
||||
|
||||
Stage.where('status IS NULL').each_batch(of: 50) do |batch|
|
||||
range = batch.pluck('MIN(id)', 'MAX(id)').first
|
||||
|
||||
Gitlab::BackgroundMigration::MigrateStageStatus.new.perform(*range)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -23,6 +23,7 @@ describe CleanStagesStatusesMigration, :migration, :sidekiq, :redis do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are no background migrations pending' do
|
||||
it 'does nothing' do
|
||||
Sidekiq::Testing.disable! do
|
||||
|
@ -32,4 +33,19 @@ describe CleanStagesStatusesMigration, :migration, :sidekiq, :redis do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are still unmigrated stages afterwards' do
|
||||
let(:stages) { table('ci_stages') }
|
||||
|
||||
before do
|
||||
stages.create!(status: nil, name: 'build')
|
||||
stages.create!(status: nil, name: 'test')
|
||||
end
|
||||
|
||||
it 'migrates statuses sequentially in batches' do
|
||||
migrate!
|
||||
|
||||
expect(migration).to have_received(:perform).once
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue