diff options
author | Felipe Artur <felipefac@gmail.com> | 2017-03-28 01:19:28 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2017-05-08 17:27:29 +0300 |
commit | 1bf2dacf2002fabf3b7bd364031d9020e5d0b624 (patch) | |
tree | 532fadb9aa10de269f4fa1aa66518d94ca7636b0 /db/post_migrate | |
parent | 24824cbb4c6d2c5ebd08dea03007f65c5df763da (diff) |
Populate merge requests head_pipeline_id
Diffstat (limited to 'db/post_migrate')
-rw-r--r-- | db/post_migrate/20170428170547_add_head_pipeline_for_each_merge_request.rb | 23 |
1 files changed, 23 insertions, 0 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 new file mode 100644 index 00000000000..0e139c28402 --- /dev/null +++ b/db/post_migrate/20170428170547_add_head_pipeline_for_each_merge_request.rb @@ -0,0 +1,23 @@ +class AddHeadPipelineForEachMergeRequest < ActiveRecord::Migration + DOWNTIME = false + + class Pipeline < ActiveRecord::Base + self.table_name = "ci_pipelines" + + def self.last_per_branch + select('ref, MAX(id) as head_id, project_id').group(:ref).group(:project_id) + end + end + + class MergeRequest < ActiveRecord::Base; end + + 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 + end + + def down + end +end |