Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2017-03-28 23:04:14 +0300
committerFelipe Artur <felipefac@gmail.com>2017-05-08 17:29:10 +0300
commitd9bebd89dfcf7e4b163b271eea3d7a5c3e99fb5d (patch)
tree94a54961d28098ea0675f2cb15ea19bbe27166e6 /db
parent1bf2dacf2002fabf3b7bd364031d9020e5d0b624 (diff)
Fix specs 2
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20170428170547_add_head_pipeline_for_each_merge_request.rb26
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