2017-06-28 09:29:04 +00:00
|
|
|
class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
|
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = false
|
2017-06-28 10:21:25 +00:00
|
|
|
BATCH_SIZE = 10000
|
2017-07-07 13:44:47 +00:00
|
|
|
RANGE_SIZE = 1000
|
2017-06-28 10:21:25 +00:00
|
|
|
MIGRATION = 'MigrateBuildStageIdReference'.freeze
|
2017-06-28 09:29:04 +00:00
|
|
|
|
2017-06-28 10:01:52 +00:00
|
|
|
disable_ddl_transaction!
|
|
|
|
|
2017-07-07 13:19:43 +00:00
|
|
|
class Build < ActiveRecord::Base
|
|
|
|
self.table_name = 'ci_builds'
|
|
|
|
include ::EachBatch
|
|
|
|
end
|
|
|
|
|
2017-07-07 07:35:28 +00:00
|
|
|
##
|
|
|
|
# It will take around 3 days to process 20M ci_builds.
|
|
|
|
#
|
2017-06-28 09:29:04 +00:00
|
|
|
def up
|
2017-07-07 13:50:33 +00:00
|
|
|
Build.where(stage_id: nil).each_batch(of: BATCH_SIZE) do |relation, index|
|
2017-07-07 13:44:47 +00:00
|
|
|
relation.each_batch(of: RANGE_SIZE) do |relation|
|
|
|
|
range = relation.pluck('MIN(id)', 'MAX(id)').first
|
2017-06-29 10:14:54 +00:00
|
|
|
|
2017-07-07 13:44:47 +00:00
|
|
|
BackgroundMigrationWorker
|
|
|
|
.perform_in(index * 2.minutes, MIGRATION, range)
|
|
|
|
end
|
2017-06-29 10:26:37 +00:00
|
|
|
end
|
2017-06-28 09:29:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
# noop
|
|
|
|
end
|
|
|
|
end
|