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

drop_invalid_vulnerabilities.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 293530f653680bfc53c648481c548e7381229c52 (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
37
# frozen_string_literal: true

# rubocop: disable Style/Documentation
class Gitlab::BackgroundMigration::DropInvalidVulnerabilities
  # rubocop: disable Gitlab/NamespacedClass
  class Vulnerability < ActiveRecord::Base
    self.table_name = "vulnerabilities"
    has_many :findings, class_name: 'VulnerabilitiesFinding', inverse_of: :vulnerability
  end

  class VulnerabilitiesFinding < ActiveRecord::Base
    self.table_name = "vulnerability_occurrences"
    belongs_to :vulnerability, class_name: 'Vulnerability', inverse_of: :findings, foreign_key: 'vulnerability_id'
  end
  # rubocop: enable Gitlab/NamespacedClass

  # rubocop: disable CodeReuse/ActiveRecord
  def perform(start_id, end_id)
    Vulnerability
      .where(id: start_id..end_id)
      .left_joins(:findings)
      .where(vulnerability_occurrences: { vulnerability_id: nil })
      .delete_all

    mark_job_as_succeeded(start_id, end_id)
  end
  # rubocop: enable CodeReuse/ActiveRecord

  private

  def mark_job_as_succeeded(*arguments)
    Gitlab::Database::BackgroundMigrationJob.mark_all_as_succeeded(
      'DropInvalidVulnerabilities',
      arguments
    )
  end
end