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 ...@@ -102,10 +102,15 @@ module Database
schemas = Database::GitlabSchema.table_schemas(all_tables) schemas = Database::GitlabSchema.table_schemas(all_tables)
if schemas.many? if schemas.many?
raise Database::PreventCrossDatabaseModification::CrossDatabaseModificationAcrossUnsupportedTablesError, message = "Cross-database data modification of '#{schemas.to_a.join(", ")}' were detected within " \
"Cross-database data modification of '#{schemas.to_a.join(", ")}' were detected within " \
"a transaction modifying the '#{all_tables.to_a.join(", ")}' tables." \ "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." "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 end
end end
......
...@@ -68,6 +68,17 @@ RSpec.describe 'Database::PreventCrossDatabaseModification' do ...@@ -68,6 +68,17 @@ RSpec.describe 'Database::PreventCrossDatabaseModification' do
end end
end.to raise_error /Cross-database data modification/ end.to raise_error /Cross-database data modification/
end 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 end
context 'when running tests with prevent_cross_database_modification', :prevent_cross_database_modification do 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