2017-06-30 12:22:23 +00:00
|
|
|
class MigrateStagesStatuses < ActiveRecord::Migration
|
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = false
|
|
|
|
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
2017-07-05 08:54:48 +00:00
|
|
|
BATCH_SIZE = 10000
|
2017-08-25 10:04:40 +00:00
|
|
|
RANGE_SIZE = 100
|
2017-07-05 08:54:48 +00:00
|
|
|
MIGRATION = 'MigrateStageStatus'.freeze
|
2017-07-04 07:20:18 +00:00
|
|
|
|
2017-07-05 08:54:48 +00:00
|
|
|
class Stage < ActiveRecord::Base
|
|
|
|
self.table_name = 'ci_stages'
|
2017-07-10 13:42:19 +00:00
|
|
|
include ::EachBatch
|
2017-06-30 12:22:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def up
|
2017-07-10 13:42:19 +00:00
|
|
|
Stage.where(status: nil).each_batch(of: BATCH_SIZE) do |relation, index|
|
|
|
|
relation.each_batch(of: RANGE_SIZE) do |batch|
|
2017-08-23 12:48:26 +00:00
|
|
|
range = batch.pluck('MIN(id)', 'MAX(id)').first
|
|
|
|
delay = index * 5.minutes
|
2017-07-05 07:11:15 +00:00
|
|
|
|
2017-08-23 12:48:26 +00:00
|
|
|
BackgroundMigrationWorker.perform_in(delay, MIGRATION, range)
|
2017-07-10 13:42:19 +00:00
|
|
|
end
|
2017-07-04 14:58:35 +00:00
|
|
|
end
|
2017-06-30 12:22:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
2017-07-05 07:11:15 +00:00
|
|
|
disable_statement_timeout
|
|
|
|
|
2017-07-31 10:23:04 +00:00
|
|
|
update_column_in_batches(:ci_stages, :status, nil)
|
2017-06-30 12:22:23 +00:00
|
|
|
end
|
|
|
|
end
|