Commit ad3aa2af authored by pbair's avatar pbair

Don't create partitions for geo rake tasks

Only attempt to create dynamic partitions in enhanced rake tasks that
don't target the geo database. This prevents the rake tasks from
breaking if the main database is not setup.
parent c999069b
...@@ -163,6 +163,11 @@ namespace :gitlab do ...@@ -163,6 +163,11 @@ namespace :gitlab do
end end
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name| ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
# We'll temporarily skip this enhancement for geo, since in some situations we
# wish to setup the geo database before the other databases have been setup,
# and partition management attempts to connect to the main database.
next if name == 'geo'
Rake::Task["db:migrate:#{name}"].enhance do Rake::Task["db:migrate:#{name}"].enhance do
Rake::Task['gitlab:db:create_dynamic_partitions'].invoke Rake::Task['gitlab:db:create_dynamic_partitions'].invoke
end end
...@@ -181,6 +186,11 @@ namespace :gitlab do ...@@ -181,6 +186,11 @@ namespace :gitlab do
end end
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name| ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
# We'll temporarily skip this enhancement for geo, since in some situations we
# wish to setup the geo database before the other databases have been setup,
# and partition management attempts to connect to the main database.
next if name == 'geo'
Rake::Task["db:schema:load:#{name}"].enhance do Rake::Task["db:schema:load:#{name}"].enhance do
Rake::Task['gitlab:db:create_dynamic_partitions'].invoke Rake::Task['gitlab:db:create_dynamic_partitions'].invoke
end end
......
...@@ -489,6 +489,20 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do ...@@ -489,6 +489,20 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
expect { run_rake_task('db:migrate:main') }.not_to raise_error expect { run_rake_task('db:migrate:main') }.not_to raise_error
end end
end end
describe 'db:migrate:geo' do
it 'does not invoke gitlab:db:create_dynamic_partitions' do
skip 'Skipping because geo database is not setup' unless geo_configured?
expect(Rake::Task['gitlab:db:create_dynamic_partitions']).not_to receive(:invoke)
expect { run_rake_task('db:migrate:geo') }.not_to raise_error
end
def geo_configured?
!!ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'geo')
end
end
end end
describe 'gitlab:db:reset_as_non_superuser' do describe 'gitlab:db:reset_as_non_superuser' do
......
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