2018-03-17 18:26:18 +05:30
|
|
|
# rubocop:disable Migration/UpdateLargeTable
|
2018-12-23 12:14:25 +05:30
|
|
|
class MigrateBuildStageReferenceAgain < ActiveRecord::Migration[4.2]
|
2017-09-10 17:25:29 +05:30
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
|
|
|
DOWNTIME = false
|
|
|
|
|
|
|
|
disable_ddl_transaction!
|
|
|
|
|
|
|
|
def up
|
|
|
|
stage_id = Arel.sql <<-SQL.strip_heredoc
|
|
|
|
(SELECT id FROM ci_stages
|
|
|
|
WHERE ci_stages.pipeline_id = ci_builds.commit_id
|
|
|
|
AND ci_stages.name = ci_builds.stage)
|
|
|
|
SQL
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
disable_statement_timeout do
|
|
|
|
update_column_in_batches(:ci_builds, :stage_id, stage_id) do |table, query|
|
|
|
|
query.where(table[:stage_id].eq(nil))
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
2018-11-20 20:47:30 +05:30
|
|
|
disable_statement_timeout do
|
|
|
|
update_column_in_batches(:ci_builds, :stage_id, nil)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|