Commit 19e25f5b authored by Yannis Roussos's avatar Yannis Roussos

Merge branch 'ab/inline-migrations' into 'master'

Inline batched migrations only in dev env

See merge request gitlab-org/gitlab!60096
parents 515f6181 542876b8
...@@ -1031,7 +1031,7 @@ module Gitlab ...@@ -1031,7 +1031,7 @@ module Gitlab
[column, temporary_name] [column, temporary_name]
end end
batched_migration = queue_batched_background_migration( queue_batched_background_migration(
'CopyColumnUsingBackgroundMigrationJob', 'CopyColumnUsingBackgroundMigrationJob',
table, table,
primary_key, primary_key,
...@@ -1040,12 +1040,6 @@ module Gitlab ...@@ -1040,12 +1040,6 @@ module Gitlab
job_interval: interval, job_interval: interval,
batch_size: batch_size, batch_size: batch_size,
sub_batch_size: sub_batch_size) sub_batch_size: sub_batch_size)
if perform_background_migration_inline?
# To ensure the schema is up to date immediately we perform the
# migration inline in dev / test environments.
Gitlab::Database::BackgroundMigration::BatchedMigrationRunner.new.run_entire_migration(batched_migration)
end
end end
# Performs a concurrent column rename when using PostgreSQL. # Performs a concurrent column rename when using PostgreSQL.
......
...@@ -248,5 +248,19 @@ namespace :gitlab do ...@@ -248,5 +248,19 @@ namespace :gitlab do
ActiveRecord::Base.clear_cache! ActiveRecord::Base.clear_cache!
ActiveRecord::Migration.verbose = verbose_was ActiveRecord::Migration.verbose = verbose_was
end end
desc 'Run all pending batched migrations'
task execute_batched_migrations: :environment do
Gitlab::Database::BackgroundMigration::BatchedMigration.active.queue_order.each do |migration|
Gitlab::AppLogger.info("Executing batched migration #{migration.id} inline")
Gitlab::Database::BackgroundMigration::BatchedMigrationRunner.new.run_entire_migration(migration)
end
end
# Only for development environments,
# we execute pending data migrations inline for convenience.
Rake::Task['db:migrate'].enhance do
Rake::Task['gitlab:db:execute_batched_migrations'].invoke if Rails.env.development?
end
end end
end end
...@@ -1902,22 +1902,6 @@ RSpec.describe Gitlab::Database::MigrationHelpers do ...@@ -1902,22 +1902,6 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
) )
end end
end end
context 'when the migration should be performed inline' do
let(:columns) { column }
it 'calls the runner to run the entire migration' do
expect(model).to receive(:perform_background_migration_inline?).and_return(true)
expect_next_instance_of(Gitlab::Database::BackgroundMigration::BatchedMigrationRunner) do |scheduler|
expect(scheduler).to receive(:run_entire_migration) do |batched_migration|
expect(batched_migration).to eq(migration_relation.last)
end
end
model.backfill_conversion_of_integer_to_bigint(table, column, batch_size: 2, sub_batch_size: 1)
end
end
end end
end end
......
...@@ -348,6 +348,26 @@ RSpec.describe 'gitlab:db namespace rake task' do ...@@ -348,6 +348,26 @@ RSpec.describe 'gitlab:db namespace rake task' do
end end
end end
describe '#execute_batched_migrations' do
subject { run_rake_task('gitlab:db:execute_batched_migrations') }
let(:migrations) { create_list(:batched_background_migration, 2) }
let(:runner) { instance_double('Gitlab::Database::BackgroundMigration::BatchedMigrationRunner') }
before do
allow(Gitlab::Database::BackgroundMigration::BatchedMigration).to receive_message_chain(:active, :queue_order).and_return(migrations)
allow(Gitlab::Database::BackgroundMigration::BatchedMigrationRunner).to receive(:new).and_return(runner)
end
it 'executes all migrations' do
migrations.each do |migration|
expect(runner).to receive(:run_entire_migration).with(migration)
end
subject
end
end
def run_rake_task(task_name, arguments = '') def run_rake_task(task_name, arguments = '')
Rake::Task[task_name].reenable Rake::Task[task_name].reenable
Rake.application.invoke_task("#{task_name}#{arguments}") Rake.application.invoke_task("#{task_name}#{arguments}")
......
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