Commit 73d31251 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Make sure all stages are migrated after a cleanup

parent 9106975d
...@@ -5,8 +5,19 @@ class CleanStagesStatusesMigration < ActiveRecord::Migration ...@@ -5,8 +5,19 @@ class CleanStagesStatusesMigration < ActiveRecord::Migration
disable_ddl_transaction! disable_ddl_transaction!
class Stage < ActiveRecord::Base
include ::EachBatch
self.table_name = 'ci_stages'
end
def up def up
Gitlab::BackgroundMigration.steal('MigrateStageStatus') 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 end
def down def down
......
...@@ -23,6 +23,7 @@ describe CleanStagesStatusesMigration, :migration, :sidekiq, :redis do ...@@ -23,6 +23,7 @@ describe CleanStagesStatusesMigration, :migration, :sidekiq, :redis do
end end
end end
end end
context 'when there are no background migrations pending' do context 'when there are no background migrations pending' do
it 'does nothing' do it 'does nothing' do
Sidekiq::Testing.disable! do Sidekiq::Testing.disable! do
...@@ -32,4 +33,19 @@ describe CleanStagesStatusesMigration, :migration, :sidekiq, :redis do ...@@ -32,4 +33,19 @@ describe CleanStagesStatusesMigration, :migration, :sidekiq, :redis do
end end
end 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 end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment