diff --git a/spec/keeps/overdue_finalize_background_migration_spec.rb b/spec/keeps/overdue_finalize_background_migration_spec.rb
index 355ce36f18749c3bfa405072eb92e20ab952768f..1025ee183318ed88bc882c08868cbf65fa2fc9ec 100644
--- a/spec/keeps/overdue_finalize_background_migration_spec.rb
+++ b/spec/keeps/overdue_finalize_background_migration_spec.rb
@@ -124,7 +124,7 @@
       let(:gitlab_schema) { 'gitlab_ci' }
 
       it 'returns the database name' do
-        expect(database_name).to eq('ci')
+        expect(database_name).to eq(database_exists?(:ci) ? 'ci' : 'main')
       end
     end
   end