debian-mirror-gitlab/lib/gitlab/background_migration/delete_orphaned_operational_vulnerabilities.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
969 B
Ruby
Raw Normal View History

2022-11-25 23:54:43 +05:30
# frozen_string_literal: true
module Gitlab
module BackgroundMigration
# Background migration for deleting orphaned operational vulnerabilities (without findings)
class DeleteOrphanedOperationalVulnerabilities < ::Gitlab::BackgroundMigration::BatchedMigrationJob
REPORT_TYPES = {
cluster_image_scanning: 7,
custom: 99
}.freeze
NOT_EXISTS_SQL = <<-SQL
NOT EXISTS (
SELECT FROM vulnerability_occurrences
WHERE "vulnerability_occurrences"."vulnerability_id" = "vulnerabilities"."id"
)
SQL
2023-01-13 00:05:48 +05:30
operation_name :delete_orphaned_operational_vulnerabilities
2022-11-25 23:54:43 +05:30
scope_to ->(relation) do
relation
.where(report_type: [REPORT_TYPES[:cluster_image_scanning], REPORT_TYPES[:custom]])
end
def perform
2023-01-13 00:05:48 +05:30
each_sub_batch do |sub_batch|
2022-11-25 23:54:43 +05:30
sub_batch
.where(NOT_EXISTS_SQL)
.delete_all
end
end
end
end
end