Commit 687278a6 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'db-configure-after-drop-tables' into 'master'

Fixes an issue where migrations instead of schema loading were run

Closes #48564

See merge request gitlab-org/gitlab-ce!20227
parents e38db196 2efe4a13
---
title: Fixes an issue where migrations instead of schema loading were run
merge_request: 20227
author:
type: changed
...@@ -46,7 +46,9 @@ namespace :gitlab do ...@@ -46,7 +46,9 @@ namespace :gitlab do
desc 'Configures the database by running migrate, or by loading the schema and seeding if needed' desc 'Configures the database by running migrate, or by loading the schema and seeding if needed'
task configure: :environment do task configure: :environment do
if ActiveRecord::Base.connection.tables.any? # Check if we have existing db tables
# The schema_migrations table will still exist if drop_tables was called
if ActiveRecord::Base.connection.tables.count > 1
Rake::Task['db:migrate'].invoke Rake::Task['db:migrate'].invoke
else else
Rake::Task['db:schema:load'].invoke Rake::Task['db:schema:load'].invoke
......
...@@ -20,7 +20,7 @@ describe 'gitlab:db namespace rake task' do ...@@ -20,7 +20,7 @@ describe 'gitlab:db namespace rake task' do
describe 'configure' do describe 'configure' do
it 'invokes db:migrate when schema has already been loaded' do it 'invokes db:migrate when schema has already been loaded' do
allow(ActiveRecord::Base.connection).to receive(:tables).and_return(['default']) allow(ActiveRecord::Base.connection).to receive(:tables).and_return(%w[table1 table2])
expect(Rake::Task['db:migrate']).to receive(:invoke) expect(Rake::Task['db:migrate']).to receive(:invoke)
expect(Rake::Task['db:schema:load']).not_to receive(:invoke) expect(Rake::Task['db:schema:load']).not_to receive(:invoke)
expect(Rake::Task['db:seed_fu']).not_to receive(:invoke) expect(Rake::Task['db:seed_fu']).not_to receive(:invoke)
...@@ -35,6 +35,14 @@ describe 'gitlab:db namespace rake task' do ...@@ -35,6 +35,14 @@ describe 'gitlab:db namespace rake task' do
expect { run_rake_task('gitlab:db:configure') }.not_to raise_error expect { run_rake_task('gitlab:db:configure') }.not_to raise_error
end end
it 'invokes db:shema:load and db:seed_fu when there is only a single table present' do
allow(ActiveRecord::Base.connection).to receive(:tables).and_return(['default'])
expect(Rake::Task['db:schema:load']).to receive(:invoke)
expect(Rake::Task['db:seed_fu']).to receive(:invoke)
expect(Rake::Task['db:migrate']).not_to receive(:invoke)
expect { run_rake_task('gitlab:db:configure') }.not_to raise_error
end
it 'does not invoke any other rake tasks during an error' do it 'does not invoke any other rake tasks during an error' do
allow(ActiveRecord::Base).to receive(:connection).and_raise(RuntimeError, 'error') allow(ActiveRecord::Base).to receive(:connection).and_raise(RuntimeError, 'error')
expect(Rake::Task['db:migrate']).not_to receive(:invoke) expect(Rake::Task['db:migrate']).not_to receive(:invoke)
......
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