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

Schedule background migration only when it is needed

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