2017-12-05 11:02:07 +00:00
|
|
|
class ScheduleBuildStageMigration < ActiveRecord::Migration
|
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = false
|
|
|
|
MIGRATION = 'MigrateBuildStage'.freeze
|
2018-01-06 13:29:35 +00:00
|
|
|
BATCH = 1000
|
2017-12-05 11:02:07 +00:00
|
|
|
|
|
|
|
class Build < ActiveRecord::Base
|
|
|
|
include EachBatch
|
|
|
|
self.table_name = 'ci_builds'
|
|
|
|
end
|
|
|
|
|
|
|
|
def change
|
|
|
|
Build.where('stage_id IS NULL').each_batch(of: BATCH) do |builds, index|
|
|
|
|
builds.pluck(:id).map { |id| [MIGRATION, [id]] }.tap do |migrations|
|
2018-01-06 13:21:45 +00:00
|
|
|
BackgroundMigrationWorker.bulk_perform_in(index.minutes, migrations)
|
2017-12-05 11:02:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|