Commit 20998ccb authored by Alexandru Croitor's avatar Alexandru Croitor

Ensure project backfilling has finished

As we have follow up backfilling migrations coming up that
depend on project namespaces being backfilled, we need to
ensure backfilling has finalized first.

Changelog: added
parent 6e2d0580
# frozen_string_literal: true
# This migration acts as a gate-keeper for other migrations related to project namespace back-filling
# so that other migrations that depend on project namespace back-filling cannot be run unless project namespace
# back-filling has finalized successfully.
class FinalizeProjectNamespacesBackfill < Gitlab::Database::Migration[1.0]
MIGRATION = 'ProjectNamespaces::BackfillProjectNamespaces'
def up
ensure_batched_background_migration_is_finished(
job_class_name: MIGRATION,
table_name: :projects,
column_name: :id,
job_arguments: [nil, 'up']
)
end
def down
# noop
end
end
c7d84b6d92566d66f69732071fe7fc6c4e5ce32475e0d2c42413c9f005aed5b0
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe FinalizeProjectNamespacesBackfill, :migration do
let(:batched_migrations) { table(:batched_background_migrations) }
let_it_be(:migration) { described_class::MIGRATION }
describe '#up' do
shared_examples 'raises migration not finished exception' do
it 'raises exception' do
expect { migrate! }.to raise_error(/Expected batched background migration for the given configuration to be marked as 'finished'/)
end
end
context 'when project namespace backfilling migration is missing' do
it 'warns migration not found' do
expect(Gitlab::AppLogger)
.to receive(:warn).with(/Could not find batched background migration for the given configuration:/)
migrate!
end
end
context 'with backfilling migration present' do
let!(:project_namespace_backfill) do
batched_migrations.create!(
job_class_name: 'ProjectNamespaces::BackfillProjectNamespaces',
table_name: :projects,
column_name: :id,
job_arguments: [nil, 'up'],
interval: 2.minutes,
min_value: 1,
max_value: 2,
batch_size: 1000,
sub_batch_size: 200,
status: 3 # finished
)
end
context 'when project namespace backfilling migration finished successfully' do
it 'does not raise exception' do
expect { migrate! }.not_to raise_error(/Expected batched background migration for the given configuration to be marked as 'finished'/)
end
end
context 'when project namespace backfilling migration is paused' do
using RSpec::Parameterized::TableSyntax
where(:status, :description) do
0 | 'paused'
1 | 'active'
4 | 'failed'
5 | 'finalizing'
end
with_them do
before do
project_namespace_backfill.update!(status: status)
end
it_behaves_like 'raises migration not finished exception'
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