Find builds that require a migration in batches
This commit is contained in:
parent
6209ff671f
commit
02bb40e2ac
|
@ -2,6 +2,8 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
|
||||||
include Gitlab::Database::MigrationHelpers
|
include Gitlab::Database::MigrationHelpers
|
||||||
|
|
||||||
DOWNTIME = false
|
DOWNTIME = false
|
||||||
|
BATCH_SIZE = 10000
|
||||||
|
MIGRATION = 'MigrateBuildStageIdReference'.freeze
|
||||||
|
|
||||||
disable_ddl_transaction!
|
disable_ddl_transaction!
|
||||||
|
|
||||||
|
@ -10,9 +12,10 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
|
||||||
end
|
end
|
||||||
|
|
||||||
def up
|
def up
|
||||||
Build.find_each do |build|
|
Build.find_in_batches(batch_size: BATCH_SIZE).with_index do |builds, batch|
|
||||||
BackgroundMigrationWorker
|
migrations = builds.map { |build| [MIGRATION, [build.id]] }
|
||||||
.perform_async('MigrateBuildStageIdReference', [build.id])
|
|
||||||
|
BackgroundMigrationWorker.perform_bulk(*migrations)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ describe MigrateStageIdReferenceInBackground, :migration, :redis do
|
||||||
let(:projects) { table(:projects) }
|
let(:projects) { table(:projects) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
stub_const('MigrateStageIdReferenceInBackground::BATCH_SIZE', 1)
|
||||||
|
|
||||||
projects.create!(id: 123, name: 'gitlab1', path: 'gitlab1')
|
projects.create!(id: 123, name: 'gitlab1', path: 'gitlab1')
|
||||||
pipelines.create!(id: 1, project_id: 123, ref: 'master', sha: 'adf43c3a')
|
pipelines.create!(id: 1, project_id: 123, ref: 'master', sha: 'adf43c3a')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue