Skip to content
Snippets Groups Projects
Commit 2270b490 authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason :baby:
Browse files

Merge branch '429361-requeue-backfill' into 'master'

parents 92d0e0ed 1add6ec1
No related branches found
No related tags found
1 merge request!135747Fix bg migration and requeue backfill migration for remediations
Pipeline #1080722941 passed
---
migration_job_name: BackfillHasRemediationsOfVulnerabilityReads
description: Backfills has_remediations column for vulnerability_reads table.
description: Backfills has_remediations column for vulnerability_reads table.
Originally introduced via https://gitlab.com/gitlab-org/gitlab/-/merge_requests/133714
RE-ran because there was a error in remediation ingestion logic.
feature_category: database
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/133714
milestone: 16.5
milestone: 16.7
queued_migration_version: 20231011142714
......@@ -9,19 +9,15 @@ class QueueBackfillHasRemediationsOfVulnerabilityReads < Gitlab::Database::Migra
restrict_gitlab_migration gitlab_schema: :gitlab_main
disable_ddl_transaction!
def up
queue_batched_background_migration(
MIGRATION,
:vulnerability_reads,
:vulnerability_id,
job_interval: DELAY_INTERVAL,
queued_migration_version: '20231011142714',
batch_size: BATCH_SIZE,
sub_batch_size: SUB_BATCH_SIZE
)
end
# per: https://docs.gitlab.com/ee/development/database/batched_background_migrations.html#requeuing-batched-background-migrations
# > When you requeue the batched background migration, turn the original queuing
# > into a no-op by clearing up the #up and #down methods of the migration
# > performing the requeuing. Otherwise, the batched background migration is
# > queued multiple times on systems that are upgrading multiple patch releases
# > at once.
#
# being re-run via https://gitlab.com/gitlab-org/gitlab/-/merge_requests/135747
def up; end
def down
delete_batched_background_migration(MIGRATION, :vulnerability_reads, :vulnerability_id, [])
end
def down; end
end
# frozen_string_literal: true
# rubocop: disable BackgroundMigration/DictionaryFile -- queued/introduced before the rule is introduced
class RequeueBackfillHasRemediationsOfVulnerabilityReads < Gitlab::Database::Migration[2.2]
milestone '16.7'
MIGRATION = "BackfillHasRemediationsOfVulnerabilityReads"
DELAY_INTERVAL = 2.minutes
BATCH_SIZE = 10_000
SUB_BATCH_SIZE = 50
restrict_gitlab_migration gitlab_schema: :gitlab_main
disable_ddl_transaction!
def up
queue_batched_background_migration(
MIGRATION,
:vulnerability_reads,
:vulnerability_id,
job_interval: DELAY_INTERVAL,
queued_migration_version: '20231031204841',
batch_size: BATCH_SIZE,
sub_batch_size: SUB_BATCH_SIZE
)
end
def down
delete_batched_background_migration(MIGRATION, :vulnerability_reads, :vulnerability_id, [])
end
end
# rubocop: enable BackgroundMigration/DictionaryFile
a1bbcd9430acc48bc271dd041c2999932d24d15bfa2ef8766d7bf9920d2d3539
\ No newline at end of file
......@@ -20,6 +20,8 @@ class BackfillHasRemediationsOfVulnerabilityReads < BatchedMigrationJob
def perform
each_sub_batch do |sub_batch|
reset_has_remediations_attribute(sub_batch)
update_query = update_query_for(sub_batch)
connection.execute(update_query)
......@@ -28,6 +30,10 @@ def perform
private
def reset_has_remediations_attribute(sub_batch)
sub_batch.update_all(has_remediations: false)
end
def update_query_for(sub_batch)
subquery = sub_batch.joins("
INNER JOIN vulnerability_occurrences ON
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
require_migration!
RSpec.describe QueueBackfillHasRemediationsOfVulnerabilityReads, feature_category: :database do
RSpec.describe RequeueBackfillHasRemediationsOfVulnerabilityReads, feature_category: :database do
let!(:batched_migration) { described_class::MIGRATION }
it 'schedules a new batched migration' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment