diff options
author | Felipe Artur <felipefac@gmail.com> | 2017-03-28 23:04:14 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2017-05-08 17:29:10 +0300 |
commit | d9bebd89dfcf7e4b163b271eea3d7a5c3e99fb5d (patch) | |
tree | 94a54961d28098ea0675f2cb15ea19bbe27166e6 /db/post_migrate | |
parent | 1bf2dacf2002fabf3b7bd364031d9020e5d0b624 (diff) |
Fix specs 2
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20170428170547_add_head_pipeline_for_each_merge_request.rb | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/db/post_migrate/20170428170547_add_head_pipeline_for_each_merge_request.rb b/db/post_migrate/20170428170547_add_head_pipeline_for_each_merge_request.rb index 0e139c28402..bc3850c0c23 100644 --- a/db/post_migrate/20170428170547_add_head_pipeline_for_each_merge_request.rb +++ b/db/post_migrate/20170428170547_add_head_pipeline_for_each_merge_request.rb @@ -1,21 +1,23 @@ class AddHeadPipelineForEachMergeRequest < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + DOWNTIME = false - class Pipeline < ActiveRecord::Base - self.table_name = "ci_pipelines" + def up + disable_statement_timeout - def self.last_per_branch - select('ref, MAX(id) as head_id, project_id').group(:ref).group(:project_id) - end - end + pipelines = Arel::Table.new(:ci_pipelines) + merge_requests = Arel::Table.new(:merge_requests) - class MergeRequest < ActiveRecord::Base; end + 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])) - def up - Pipeline.last_per_branch.each do |pipeline| - mrs = MergeRequest.where(source_branch: pipeline.ref, source_project_id: pipeline.project_id) - mrs.update_all(head_pipeline_id: pipeline.head_id) - end + sub_query = Arel::Nodes::SqlLiteral.new(Arel::Nodes::Grouping.new(head_id).to_sql) + + update_column_in_batches(:merge_requests, :head_pipeline_id, sub_query) end def down |