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