diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-09-18 13:47:46 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-09-18 13:47:46 +0200 |
commit | 73d31251af6e0574423990836e56350b8ffbea41 (patch) | |
tree | 833d13aeb803afb63774a5cdbb4ca5e5cece3f7a | |
parent | 9106975d3caacdda43ed6c0387d741f6c0795d27 (diff) | |
download | gitlab-ce-73d31251af6e0574423990836e56350b8ffbea41.tar.gz |
Make sure all stages are migrated after a cleanupbackstage/gb/steal-stages-statuses-migration
-rw-r--r-- | db/migrate/20170912113435_clean_stages_statuses_migration.rb | 11 | ||||
-rw-r--r-- | spec/migrations/clean_stages_statuses_migration_spec.rb | 16 |
2 files changed, 27 insertions, 0 deletions
diff --git a/db/migrate/20170912113435_clean_stages_statuses_migration.rb b/db/migrate/20170912113435_clean_stages_statuses_migration.rb index 31fd240d3dc..fc091d7894e 100644 --- a/db/migrate/20170912113435_clean_stages_statuses_migration.rb +++ b/db/migrate/20170912113435_clean_stages_statuses_migration.rb @@ -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 diff --git a/spec/migrations/clean_stages_statuses_migration_spec.rb b/spec/migrations/clean_stages_statuses_migration_spec.rb index 822a188e67d..38705f8eaae 100644 --- a/spec/migrations/clean_stages_statuses_migration_spec.rb +++ b/spec/migrations/clean_stages_statuses_migration_spec.rb @@ -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 |