Welcome to mirror list, hosted at ThFree Co, Russian Federation.

delete_orphans_approval_merge_request_rules2.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a882b61c67d23ea8e6366deb1707a294a5cceed3 (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
29
30
31
32
33
34
35
36
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # Deletes orphans records whenever report_type equals to scan_finding (4) or license_scanning (2)
    class DeleteOrphansApprovalMergeRequestRules2 < BatchedMigrationJob
      LICENSE_SCANNING_REPORT_TYPE = 2
      SCAN_FINDING_REPORT_TYPE = 4

      scope_to ->(relation) {
                 relation.where(report_type: [LICENSE_SCANNING_REPORT_TYPE, SCAN_FINDING_REPORT_TYPE],
                   security_orchestration_policy_configuration_id: nil)
               }

      operation_name :delete_all
      feature_category :database

      # rubocop: disable Style/Documentation
      class ApprovalMergeRequestRuleSource < ::ApplicationRecord
        # rubocop: enable Style/Documentation

        self.table_name = 'approval_merge_request_rule_sources'
      end

      def perform
        each_sub_batch do |sub_batch|
          ApprovalMergeRequestRuleSource
            .where(approval_merge_request_rule_id: sub_batch.distinct.select(:id))
            .delete_all

          sub_batch.delete_all
        end
      end
    end
  end
end