Commit 02bb40e2 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Find builds that require a migration in batches

parent 6209ff67
......@@ -2,6 +2,8 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
BATCH_SIZE = 10000
MIGRATION = 'MigrateBuildStageIdReference'.freeze
disable_ddl_transaction!
......@@ -10,9 +12,10 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
end
def up
Build.find_each do |build|
BackgroundMigrationWorker
.perform_async('MigrateBuildStageIdReference', [build.id])
Build.find_in_batches(batch_size: BATCH_SIZE).with_index do |builds, batch|
migrations = builds.map { |build| [MIGRATION, [build.id]] }
BackgroundMigrationWorker.perform_bulk(*migrations)
end
end
......
......@@ -8,6 +8,8 @@ describe MigrateStageIdReferenceInBackground, :migration, :redis do
let(:projects) { table(:projects) }
before do
stub_const('MigrateStageIdReferenceInBackground::BATCH_SIZE', 1)
projects.create!(id: 123, name: 'gitlab1', path: 'gitlab1')
pipelines.create!(id: 1, project_id: 123, ref: 'master', sha: 'adf43c3a')
......
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