Commit b08d9f84 authored by Dylan Griffith's avatar Dylan Griffith

Improve cross-modification error message for undefined gitlab_schema

This can cause confusion for developers adding new tables at present
because the error message doesn't make it clear that the problem (and
hence solution) is just about the table being missing from
`spec/support/database/gitlab_schemas.yml`.
parent 817d5d87
......@@ -102,10 +102,15 @@ module Database
schemas = Database::GitlabSchema.table_schemas(all_tables)
if schemas.many?
raise Database::PreventCrossDatabaseModification::CrossDatabaseModificationAcrossUnsupportedTablesError,
"Cross-database data modification of '#{schemas.to_a.join(", ")}' were detected within " \
message = "Cross-database data modification of '#{schemas.to_a.join(", ")}' were detected within " \
"a transaction modifying the '#{all_tables.to_a.join(", ")}' tables." \
"Please refer to https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-cross-database-transactions for details on how to resolve this exception."
if schemas.any? { |s| s.to_s.start_with?("undefined") }
message += " The gitlab_schema was undefined for one or more of the tables in this transaction. Any new tables must be added to spec/support/database/gitlab_schemas.yml ."
end
raise Database::PreventCrossDatabaseModification::CrossDatabaseModificationAcrossUnsupportedTablesError, message
end
end
end
......
......@@ -68,6 +68,17 @@ RSpec.describe 'Database::PreventCrossDatabaseModification' do
end
end.to raise_error /Cross-database data modification/
end
it 'raises an error when an undefined gitlab_schema table is modified with another table' do
expect do
with_cross_database_modification_prevented do
Project.transaction do
project.touch
project.connection.execute('UPDATE foo_bars_undefined_table SET a=1 WHERE id = -1')
end
end
end.to raise_error /Cross-database data modification.*The gitlab_schema was undefined/
end
end
context 'when running tests with prevent_cross_database_modification', :prevent_cross_database_modification 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