gitlab-org--gitlab-foss/db/post_migrate/20220314154235_migrate_vuln...

41 lines
1.1 KiB
Ruby

# frozen_string_literal: true
# See https://docs.gitlab.com/ee/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class MigrateVulnerabilityApprovalRules < Gitlab::Database::Migration[2.0]
disable_ddl_transaction!
restrict_gitlab_migration gitlab_schema: :gitlab_main
WORKER_DELAY = 30.seconds
class ApprovalProjectRule < ActiveRecord::Base
self.table_name = 'approval_project_rules'
end
def up
return unless Gitlab.ee?
return unless generate_scan_finding_rule_worker
ApprovalProjectRule.reset_column_information
# Based on enum report_type: { vulnerability: 1, license_scanning: 2, code_coverage: 3, scan_finding: 4 }
ApprovalProjectRule.where(report_type: 1).find_each.each_with_index do |rule, index|
generate_scan_finding_rule_worker.perform_in(WORKER_DELAY * index, rule.id)
end
end
def down
# no-op
# Vulnerability-Check feature has been removed as part of 15.0
end
private
def generate_scan_finding_rule_worker
@generate_scan_finding_rule_worker ||= "Security::GenerateScanFindingRulesWorker".safe_constantize
end
end