Commit 4370053e authored by Kerri Miller's avatar Kerri Miller

Merge branch 'pb-properly-enhance-multidb-rake-tasks' into 'master'

Properly enhance multi-db partitioning rake tasks

See merge request gitlab-org/gitlab!80677
parents 92914b5a a3e305b7
...@@ -152,6 +152,12 @@ namespace :gitlab do ...@@ -152,6 +152,12 @@ namespace :gitlab do
Rake::Task['gitlab:db:create_dynamic_partitions'].invoke Rake::Task['gitlab:db:create_dynamic_partitions'].invoke
end end
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
Rake::Task["db:migrate:#{name}"].enhance do
Rake::Task['gitlab:db:create_dynamic_partitions'].invoke
end
end
# When we load the database schema from db/structure.sql # When we load the database schema from db/structure.sql
# we don't have any dynamic partitions created. We don't really need to # we don't have any dynamic partitions created. We don't really need to
# because application initializers/sidekiq take care of that, too. # because application initializers/sidekiq take care of that, too.
...@@ -160,15 +166,15 @@ namespace :gitlab do ...@@ -160,15 +166,15 @@ namespace :gitlab do
# #
# Other than that it's helpful to create partitions early when bootstrapping # Other than that it's helpful to create partitions early when bootstrapping
# a new installation. # a new installation.
# Rake::Task['db:schema:load'].enhance do
# Rails 6.1 deprecates db:structure:load in favor of db:schema:load
Rake::Task['db:structure:load'].enhance do
Rake::Task['gitlab:db:create_dynamic_partitions'].invoke Rake::Task['gitlab:db:create_dynamic_partitions'].invoke
end end
Rake::Task['db:schema:load'].enhance do ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
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
end
desc "Clear all connections" desc "Clear all connections"
task :clear_all_connections do task :clear_all_connections do
......
...@@ -430,13 +430,11 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do ...@@ -430,13 +430,11 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
context 'with multiple databases', :reestablished_active_record_base do context 'with multiple databases', :reestablished_active_record_base do
before do before do
allow(ActiveRecord::Tasks::DatabaseTasks).to receive(:setup_initial_database_yaml).and_return([:main, :geo]) skip_if_multiple_databases_not_setup
end end
describe 'db:structure:dump' do describe 'db:structure:dump' do
it 'invokes gitlab:db:clean_structure_sql' do it 'invokes gitlab:db:clean_structure_sql' do
skip unless Gitlab.ee?
expect(Rake::Task['gitlab:db:clean_structure_sql']).to receive(:invoke).twice.and_return(true) expect(Rake::Task['gitlab:db:clean_structure_sql']).to receive(:invoke).twice.and_return(true)
expect { run_rake_task('db:structure:dump:main') }.not_to raise_error expect { run_rake_task('db:structure:dump:main') }.not_to raise_error
...@@ -445,13 +443,19 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do ...@@ -445,13 +443,19 @@ RSpec.describe 'gitlab:db namespace rake task', :silence_stdout do
describe 'db:schema:dump' do describe 'db:schema:dump' do
it 'invokes gitlab:db:clean_structure_sql' do it 'invokes gitlab:db:clean_structure_sql' do
skip unless Gitlab.ee?
expect(Rake::Task['gitlab:db:clean_structure_sql']).to receive(:invoke).once.and_return(true) expect(Rake::Task['gitlab:db:clean_structure_sql']).to receive(:invoke).once.and_return(true)
expect { run_rake_task('db:schema:dump:main') }.not_to raise_error expect { run_rake_task('db:schema:dump:main') }.not_to raise_error
end end
end end
describe 'db:migrate' do
it 'invokes gitlab:db:create_dynamic_partitions' do
expect(Rake::Task['gitlab:db:create_dynamic_partitions']).to receive(:invoke).once.and_return(true)
expect { run_rake_task('db:migrate:main') }.not_to raise_error
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