Commit 74bbd963 authored by Michał Zając's avatar Michał Zając

Fix argument type for background migration

Follow up to https://gitlab.com/gitlab-org/gitlab/-/issues/277327 where
we got the argument type to `migrate_in` wrong (it uses splat instead of
a named argument).
parent c4eb06e4
---
title: Fix argument type for background migration
merge_request: 55097
author:
type: fixed
...@@ -11,13 +11,7 @@ class ScheduleUuidPopulationForSecurityFindings < ActiveRecord::Migration[6.0] ...@@ -11,13 +11,7 @@ class ScheduleUuidPopulationForSecurityFindings < ActiveRecord::Migration[6.0]
disable_ddl_transaction! disable_ddl_transaction!
def up def up
Gitlab::BackgroundMigration::PopulateUuidsForSecurityFindings.security_findings.each_batch(column: :scan_id, of: BATCH_SIZE) do |batch, index| # no-op, replaced by 20210111075206_schedule_uuid_population_for_security_findings2.rb
migrate_in(
DELAY_INTERVAL * index,
MIGRATION_CLASS,
batch.pluck(:scan_id)
)
end
end end
def down def down
......
# frozen_string_literal: true
# This replaces the previous post-deployment migration 20210111075105_schedule_uuid_population_for_security_findings.rb,
# we have to run this again due to a bug in how we were receiving the arguments in the background migration.
class ScheduleUuidPopulationForSecurityFindings2 < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
MIGRATION_CLASS = 'PopulateUuidsForSecurityFindings'
DELAY_INTERVAL = 2.minutes
BATCH_SIZE = 25
disable_ddl_transaction!
def up
::Gitlab::BackgroundMigration.steal(MIGRATION_CLASS) do |job|
job.delete
false
end
Gitlab::BackgroundMigration::PopulateUuidsForSecurityFindings.security_findings.each_batch(column: :scan_id, of: BATCH_SIZE) do |batch, index|
migrate_in(
DELAY_INTERVAL * index,
MIGRATION_CLASS,
batch.pluck(:scan_id)
)
end
end
def down
# no-op
end
end
9da5955d9f71d671a41e6d03f76f87370d6e67b6853707adb164f7ffa8c75082
\ No newline at end of file
...@@ -228,7 +228,7 @@ module EE ...@@ -228,7 +228,7 @@ module EE
end end
override :perform override :perform
def perform(scan_ids) def perform(*scan_ids)
SecurityScan.where(id: scan_ids).includes(:pipeline, :artifacts).each(&:recover_findings) SecurityScan.where(id: scan_ids).includes(:pipeline, :artifacts).each(&:recover_findings)
log_info(scan_ids.count) log_info(scan_ids.count)
......
...@@ -54,7 +54,7 @@ RSpec.describe ::Gitlab::BackgroundMigration::PopulateUuidsForSecurityFindings d ...@@ -54,7 +54,7 @@ RSpec.describe ::Gitlab::BackgroundMigration::PopulateUuidsForSecurityFindings d
end end
describe '#perform' do describe '#perform' do
subject(:populate_uuids) { described_class.new.perform([security_scan_1.id, security_scan_2.id, security_scan_3.id]) } subject(:populate_uuids) { described_class.new.perform(security_scan_1.id, security_scan_2.id, security_scan_3.id) }
it 'sets the `uuid` of findings' do it 'sets the `uuid` of findings' do
expect { populate_uuids }.to change { finding_1.reload.uuid }.from(nil) expect { populate_uuids }.to change { finding_1.reload.uuid }.from(nil)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
require_migration! require_migration!
RSpec.describe ScheduleUuidPopulationForSecurityFindings do RSpec.describe ScheduleUuidPopulationForSecurityFindings2 do
let(:namespaces) { table(:namespaces) } let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) } let(:projects) { table(:projects) }
let(:ci_pipelines) { table(:ci_pipelines) } let(:ci_pipelines) { table(:ci_pipelines) }
......
...@@ -10,7 +10,7 @@ module Gitlab ...@@ -10,7 +10,7 @@ module Gitlab
NOP_RELATION.new NOP_RELATION.new
end end
def perform(_scan_ids); end def perform(*_scan_ids); end
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment