diff options
Diffstat (limited to 'db/post_migrate/20170428170547_add_head_pipeline_for_each_merge_request.rb')
-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 |