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 /lib | |
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 'lib')
-rw-r--r-- | lib/gitlab/background_migration/populate_merge_request_assignees_table.rb | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/populate_merge_request_assignees_table.rb b/lib/gitlab/background_migration/populate_merge_request_assignees_table.rb new file mode 100644 index 00000000000..a4c6540c61b --- /dev/null +++ b/lib/gitlab/background_migration/populate_merge_request_assignees_table.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # This background migration creates records on merge_request_assignees according + # to the given merge request IDs range. A _single_ INSERT is issued for the given range. + # This is required for supporting multiple assignees on merge requests. + class PopulateMergeRequestAssigneesTable + def perform(from_id, to_id) + select_sql = + MergeRequest + .where(merge_request_assignees_not_exists_clause) + .where(id: from_id..to_id) + .where('assignee_id IS NOT NULL') + .select(:id, :assignee_id) + .to_sql + + execute("INSERT INTO merge_request_assignees (merge_request_id, user_id) #{select_sql}") + end + + private + + def merge_request_assignees_not_exists_clause + <<~SQL + NOT EXISTS (SELECT 1 FROM merge_request_assignees + WHERE merge_request_assignees.merge_request_id = merge_requests.id) + SQL + end + + def execute(sql) + @connection ||= ActiveRecord::Base.connection + @connection.execute(sql) + end + end + end +end |