summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration/populate_issue_email_participants.rb
blob: 0a56ac1dae827edcb6571941bd8c9db0b21cc96a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # Class to migrate service_desk_reply_to email addresses to issue_email_participants
    class PopulateIssueEmailParticipants
      # rubocop:disable Style/Documentation
      class TmpIssue < ActiveRecord::Base
        self.table_name = 'issues'
      end

      def perform(start_id, stop_id)
        issues = TmpIssue.select(:id, :service_desk_reply_to, :created_at).where(id: (start_id..stop_id)).where.not(service_desk_reply_to: nil)

        rows = issues.map do |issue|
          {
            issue_id: issue.id,
            email: issue.service_desk_reply_to,
            created_at: issue.created_at,
            updated_at: issue.created_at
          }
        end

        Gitlab::Database.main.bulk_insert(:issue_email_participants, rows, on_conflict: :do_nothing) # rubocop:disable Gitlab/BulkInsert
      end
    end
  end
end