# frozen_string_literal: true

module EE
  module Gitlab
    module BackgroundMigration
      module RemoveUndefinedVulnerabilitySeverityLevel
        extend ::Gitlab::Utils::Override
        class Vulnerability < ActiveRecord::Base
          include ::EachBatch

          self.table_name = 'vulnerabilities'

          SEVERITY_LEVELS = {
            undefined: 0,
            unknown: 2
          }.with_indifferent_access.freeze

          enum severity: SEVERITY_LEVELS

          def self.undefined_severity
            where(severity: Vulnerability.severities[:undefined])
          end
        end

        override :perform
        def perform(start_id, stop_id)
          Vulnerability.undefined_severity
            .where(id: start_id..stop_id)
            .update_all(severity: Vulnerability.severities[:unknown])
        end
      end
    end
  end
end
