rename_column_concurrently not supporting decomposed database
1. CrossSchemaAccessError
While testing/running database migrations Gitlab::Database::Migration[2.0]
with (rename_column_concurrently
) the Gitlab::database::QueryAnalyzers::GitlabSchemasValidateConnection::CrossSchemaAccessError
has been raised:
- during tests
- running migrations locally
Steps to reproduce
- Create a database migration with
rename_column_concurrently
- Run the migrations
- Catch the error
Migration example
# frozen_string_literal: true
class RenameWebHooksServiceIdToIntegrationId < Gitlab::Database::Migration[2.0]
disable_ddl_transaction!
def up
rename_column_concurrently :web_hooks, :service_id, :integration_id
end
def down
undo_rename_column_concurrently :web_hooks, :service_id, :integration_id
end
end
Proposed solution:
Update migration_helpers.rb
with the following code:
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index 4bb1d71ce185..ea1beeaf81e6 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -1666,7 +1666,9 @@ def create_column_from(table, old, new, type: nil, batch_column_name: :id, type_
end
Gitlab::Database::QueryAnalyzers::RestrictAllowedSchemas.with_suppressed do
- update_column_in_batches(table, new, old_value, batch_column_name: batch_column_name)
+ Gitlab::Database::QueryAnalyzers::GitlabSchemasValidateConnection.with_suppressed do
+ update_column_in_batches(table, new, old_value, batch_column_name: batch_column_name)
+ end
end
add_not_null_constraint(table, new) unless old_col.null
2. The called method update_column_in_batches will cause errors on Staging/Production
This method will be called to copy the data from the old column into the new column on both databases (main, ci), but the table on one of the databases (ci in this case) is write-protected, and it will cause error. It has been locked against writes using this rake task to prevent writes on the wrong database.
To solve this problem, another MR will address this problem by disabling this trigger temporarily while copying the data
Edited by Omar Qunsul