2017-11-17 13:38:14 +00:00
|
|
|
# rubocop:disable Migration/UpdateLargeTable
|
2017-06-21 11:55:28 +00:00
|
|
|
class MigrateBuildStageReferenceAgain < ActiveRecord::Migration
|
|
|
|
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-08-10 23:45:46 +00:00
|
|
|
disable_statement_timeout do
|
2018-07-09 21:31:45 +00:00
|
|
|
update_column_in_batches(:ci_builds, :stage_id, stage_id) do |table, query|
|
|
|
|
query.where(table[:stage_id].eq(nil))
|
|
|
|
end
|
2017-06-21 11:55:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
2018-08-10 23:45:46 +00:00
|
|
|
disable_statement_timeout do
|
2018-07-09 21:31:45 +00:00
|
|
|
update_column_in_batches(:ci_builds, :stage_id, nil)
|
|
|
|
end
|
2017-06-21 11:55:28 +00:00
|
|
|
end
|
|
|
|
end
|