2017-11-17 13:38:14 +00:00
|
|
|
# rubocop:disable Migration/UpdateLargeTable
|
2017-03-27 22:19:28 +00:00
|
|
|
class AddHeadPipelineForEachMergeRequest < ActiveRecord::Migration
|
2017-03-28 20:04:14 +00:00
|
|
|
include Gitlab::Database::MigrationHelpers
|
|
|
|
|
2017-03-27 22:19:28 +00:00
|
|
|
DOWNTIME = false
|
|
|
|
|
2017-06-21 12:35:06 +00:00
|
|
|
disable_ddl_transaction!
|
|
|
|
|
2017-03-28 20:04:14 +00:00
|
|
|
def up
|
|
|
|
pipelines = Arel::Table.new(:ci_pipelines)
|
|
|
|
merge_requests = Arel::Table.new(:merge_requests)
|
2017-03-27 22:19:28 +00:00
|
|
|
|
2018-08-10 23:45:46 +00:00
|
|
|
disable_statement_timeout do
|
2018-07-09 21:31:45 +00:00
|
|
|
head_id = pipelines
|
|
|
|
.project(Arel::Nodes::NamedFunction.new('max', [pipelines[:id]]))
|
|
|
|
.from(pipelines)
|
|
|
|
.where(pipelines[:ref].eq(merge_requests[:source_branch]))
|
|
|
|
.where(pipelines[:project_id].eq(merge_requests[:source_project_id]))
|
2017-03-27 22:19:28 +00:00
|
|
|
|
2018-07-09 21:31:45 +00:00
|
|
|
sub_query = Arel::Nodes::SqlLiteral.new(Arel::Nodes::Grouping.new(head_id).to_sql)
|
2017-03-28 20:04:14 +00:00
|
|
|
|
2018-07-09 21:31:45 +00:00
|
|
|
update_column_in_batches(:merge_requests, :head_pipeline_id, sub_query)
|
|
|
|
end
|
2017-03-27 22:19:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
end
|
|
|
|
end
|