Commit 8ce92324 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'finalize_backfill_project_namespaces' into 'master'

Ensure project backfilling has finished

See merge request gitlab-org/gitlab!82176
parents 999ba7c1 20998ccb
# 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