Skip to content
Snippets Groups Projects
Commit b28cf373 authored by Pavel Shutsin's avatar Pavel Shutsin :two:
Browse files

Merge branch '396351-no-ddl-transaction-for-batch-migrations' into 'master'

Require disable_ddl_transaction on bbm finalization

See merge request gitlab-org/gitlab!114558



Merged-by: Pavel Shutsin's avatarPavel Shutsin <pshutsin@gitlab.com>
Approved-by: Pavel Shutsin's avatarPavel Shutsin <pshutsin@gitlab.com>
Co-authored-by: default avatarMarius Bobin <mbobin@gitlab.com>
parents c786955d b9614c8b
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
class EnsureTimelogsNoteIdBigintBackfillIsFinishedForGitlabDotCom < Gitlab::Database::Migration[2.1]
restrict_gitlab_migration gitlab_schema: :gitlab_main
disable_ddl_transaction!
def up
return unless should_run?
......
......@@ -201,6 +201,12 @@ def gitlab_schema_from_context
def ensure_batched_background_migration_is_finished(job_class_name:, table_name:, column_name:, job_arguments:, finalize: true)
Gitlab::Database::QueryAnalyzers::RestrictAllowedSchemas.require_dml_mode!
if transaction_open?
raise 'The `ensure_batched_background_migration_is_finished` cannot be run inside a transaction. ' \
'You can disable transactions by calling `disable_ddl_transaction!` in the body of ' \
'your migration class.'
end
Gitlab::Database::BackgroundMigration::BatchedMigration.reset_column_information
migration = Gitlab::Database::BackgroundMigration::BatchedMigration.find_for_configuration(
Gitlab::Database.gitlab_schemas_for_connection(connection),
......
......@@ -513,6 +513,17 @@ def self.name
end
end
context 'when within transaction' do
before do
allow(migration).to receive(:transaction_open?).and_return(true)
end
it 'does raise an exception' do
expect { ensure_batched_background_migration_is_finished }
.to raise_error /`ensure_batched_background_migration_is_finished` cannot be run inside a transaction./
end
end
it 'finalizes the migration' do
expect(Gitlab::Database::QueryAnalyzers::RestrictAllowedSchemas).to receive(:require_dml_mode!).twice
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment