diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2019-03-22 13:51:47 -0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2019-03-25 19:50:40 -0300 |
commit | 929ee4d18da886826e9fcc15c35b4d4024bc8237 (patch) | |
tree | 362d6627f738a968fea914e4b264789b1bb6b2a4 /app | |
parent | 09d25b04c34398f9f825b3cc95265af3097fa035 (diff) | |
download | gitlab-ce-929ee4d18da886826e9fcc15c35b4d4024bc8237.tar.gz |
Add multiple assignees migration and table population
This will be further required for supporting multi-assignees MRs
Diffstat (limited to 'app')
-rw-r--r-- | app/models/merge_request.rb | 15 | ||||
-rw-r--r-- | app/models/merge_request_assignee.rb | 6 |
2 files changed, 21 insertions, 0 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 5f6d5095bcc..2c0692e1b45 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -67,6 +67,8 @@ class MergeRequest < ActiveRecord::Base has_many :cached_closes_issues, through: :merge_requests_closing_issues, source: :issue has_many :merge_request_pipelines, foreign_key: 'merge_request_id', class_name: 'Ci::Pipeline' + has_many :merge_request_assignees + # Will be deprecated at https://gitlab.com/gitlab-org/gitlab-ce/issues/59457 belongs_to :assignee, class_name: "User" serialize :merge_params, Hash # rubocop:disable Cop/ActiveRecordSerialize @@ -76,6 +78,10 @@ class MergeRequest < ActiveRecord::Base after_update :reload_diff_if_branch_changed after_save :ensure_metrics + # Required until the codebase starts using this relation for single or multiple assignees. + # TODO: Remove at gitlab-ee#2004 implementation. + after_save :refresh_merge_request_assignees, if: :assignee_id_changed? + # When this attribute is true some MR validation is ignored # It allows us to close or modify broken merge requests attr_accessor :allow_broken @@ -675,6 +681,15 @@ class MergeRequest < ActiveRecord::Base merge_request_diff || create_merge_request_diff end + def refresh_merge_request_assignees + transaction do + # Using it instead relation.delete_all in order to avoid adding a + # dependent: :delete_all (we already have foreign key cascade deletion). + MergeRequestAssignee.where(merge_request_id: self).delete_all + merge_request_assignees.create(user_id: assignee_id) if assignee_id + end + end + def create_merge_request_diff fetch_ref! diff --git a/app/models/merge_request_assignee.rb b/app/models/merge_request_assignee.rb new file mode 100644 index 00000000000..f0e6be51b7f --- /dev/null +++ b/app/models/merge_request_assignee.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class MergeRequestAssignee < ApplicationRecord + belongs_to :merge_request + belongs_to :assignee, class_name: "User", foreign_key: :user_id +end |