Commit 1dc20f7a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Schedule background migration only when it is needed

parent 9a32ca40
......@@ -12,11 +12,13 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
end
def up
Build.find_in_batches(batch_size: BATCH_SIZE).with_index do |builds, batch|
migrations = builds.map { |build| [MIGRATION, [build.id]] }
Build.where(stage_id: nil)
.find_in_batches(batch_size: BATCH_SIZE)
.with_index do |builds, batch|
migrations = builds.map { |build| [MIGRATION, [build.id]] }
BackgroundMigrationWorker.perform_bulk(*migrations)
end
BackgroundMigrationWorker.perform_bulk(*migrations)
end
end
def down
......
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