diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-03-26 18:00:46 +0000 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-03-26 18:00:46 +0000 |
commit | 19010942652c23d203c856acf454528ef342fafb (patch) | |
tree | 4b6f1e5319ef050faf6336d3020291701e787e9f /app | |
parent | 61ffcebd5e577df23b39b289a1d6e203a9073ef0 (diff) | |
parent | 929ee4d18da886826e9fcc15c35b4d4024bc8237 (diff) | |
download | gitlab-ce-19010942652c23d203c856acf454528ef342fafb.tar.gz |
Merge branch 'osw-multi-assignees-merge-requests-migration' into 'master'
Add multiple MR assignees migration and background table population
See merge request gitlab-org/gitlab-ce!26496
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 |