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

backfill_cluster_agents_has_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: 249c9d7af576afacaae7ced86ae8690cecea9a31 (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
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # Backfills the `vulnerability_reads.casted_cluster_agent_id` column
    class BackfillClusterAgentsHasVulnerabilities < Gitlab::BackgroundMigration::BatchedMigrationJob
      VULNERABILITY_READS_JOIN = <<~SQL
        INNER JOIN vulnerability_reads
        ON vulnerability_reads.casted_cluster_agent_id = cluster_agents.id AND
        vulnerability_reads.project_id = cluster_agents.project_id AND
        vulnerability_reads.report_type = 7
      SQL

      RELATION = ->(relation) do
        relation
          .where(has_vulnerabilities: false)
      end

      operation_name :update_all

      def perform
        each_sub_batch(batching_scope: RELATION) do |sub_batch|
          sub_batch
            .joins(VULNERABILITY_READS_JOIN)
            .update_all(has_vulnerabilities: true)
        end
      end
    end
  end
end