diff options
Diffstat (limited to 'lib/gitlab/background_migration/delete_orphans_approval_project_rules2.rb')
-rw-r--r-- | lib/gitlab/background_migration/delete_orphans_approval_project_rules2.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/delete_orphans_approval_project_rules2.rb b/lib/gitlab/background_migration/delete_orphans_approval_project_rules2.rb new file mode 100644 index 00000000000..f6b7e184811 --- /dev/null +++ b/lib/gitlab/background_migration/delete_orphans_approval_project_rules2.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # Deletes orphans records whenever report_type equals to scan_finding (4) or license_scanning (2) + # rubocop: disable CodeReuse/ActiveRecord + class DeleteOrphansApprovalProjectRules2 < 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_project_rule_id: sub_batch.distinct.select(:id)) + .delete_all + + sub_batch.delete_all + end + end + end + # rubocop: enable CodeReuse/ActiveRecord + end +end |