Commit 8e93523b authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'add-migration-for-marking-signature-recalculations-as-complete' into 'master'

chore: Mark previous Recalculation background migrations as succeeded

See merge request gitlab-org/gitlab!77052
parents 8c69151e 4d50836b
# frozen_string_literal: true
class MarkRecalculateFindingSignaturesAsCompleted < Gitlab::Database::Migration[1.0]
MIGRATION = 'RecalculateVulnerabilitiesOccurrencesUuid'
def up
# Only run migration for Gitlab.com
return unless ::Gitlab.com?
# In previous migration marking jobs as successful was missed
Gitlab::Database::BackgroundMigrationJob
.for_migration_class(MIGRATION)
.pending
.update_all(status: :succeeded)
end
def down
# no-op
end
end
649360f4069aac4784f4d039015f8dda3f4bae28e8132f841e25b48f034a392e
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require_migration!
def create_background_migration_jobs(ids, status, created_at)
proper_status = case status
when :pending
Gitlab::Database::BackgroundMigrationJob.statuses['pending']
when :succeeded
Gitlab::Database::BackgroundMigrationJob.statuses['succeeded']
else
raise ArgumentError
end
background_migration_jobs.create!(
class_name: 'RecalculateVulnerabilitiesOccurrencesUuid',
arguments: Array(ids),
status: proper_status,
created_at: created_at
)
end
RSpec.describe MarkRecalculateFindingSignaturesAsCompleted, :migration do
let_it_be(:background_migration_jobs) { table(:background_migration_jobs) }
context 'when RecalculateVulnerabilitiesOccurrencesUuid jobs are present' do
before do
create_background_migration_jobs([1, 2, 3], :succeeded, DateTime.new(2021, 5, 5, 0, 2))
create_background_migration_jobs([4, 5, 6], :pending, DateTime.new(2021, 5, 5, 0, 4))
create_background_migration_jobs([1, 2, 3], :succeeded, DateTime.new(2021, 8, 18, 0, 0))
create_background_migration_jobs([4, 5, 6], :pending, DateTime.new(2021, 8, 18, 0, 2))
create_background_migration_jobs([7, 8, 9], :pending, DateTime.new(2021, 8, 18, 0, 4))
end
describe 'gitlab.com' do
before do
allow(::Gitlab).to receive(:com?).and_return(true)
end
it 'marks all jobs as succeeded' do
expect(background_migration_jobs.where(status: 1).count).to eq(2)
migrate!
expect(background_migration_jobs.where(status: 1).count).to eq(5)
end
end
describe 'self managed' do
before do
allow(::Gitlab).to receive(:com?).and_return(false)
end
it 'does not change job status' do
expect(background_migration_jobs.where(status: 1).count).to eq(2)
migrate!
expect(background_migration_jobs.where(status: 1).count).to eq(2)
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