summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-18 08:17:02 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-18 08:17:02 +0000
commitb39512ed755239198a9c294b6a45e65c05900235 (patch)
treed234a3efade1de67c46b9e5a38ce813627726aa7 /lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent.rb
parentd31474cf3b17ece37939d20082b07f6657cc79a9 (diff)
downloadgitlab-ce-b39512ed755239198a9c294b6a45e65c05900235.tar.gz
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent.rb')
-rw-r--r--lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent.rb b/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent.rb
new file mode 100644
index 00000000000..728b60f7a0e
--- /dev/null
+++ b/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BackgroundMigration
+ # Backfills the `vulnerability_reads.casted_cluster_agent_id` column
+ class BackfillVulnerabilityReadsClusterAgent < Gitlab::BackgroundMigration::BatchedMigrationJob
+ CLUSTER_AGENTS_JOIN = <<~SQL
+ INNER JOIN cluster_agents
+ ON CAST(vulnerability_reads.cluster_agent_id AS bigint) = cluster_agents.id AND
+ vulnerability_reads.project_id = cluster_agents.project_id
+ SQL
+
+ RELATION = ->(relation) do
+ relation
+ .where(report_type: 7)
+ end
+
+ def perform
+ each_sub_batch(
+ operation_name: :update_all,
+ batching_scope: RELATION
+ ) do |sub_batch|
+ sub_batch
+ .joins(CLUSTER_AGENTS_JOIN)
+ .update_all('casted_cluster_agent_id = CAST(vulnerability_reads.cluster_agent_id AS bigint)')
+ end
+ end
+ end
+ end
+end