Commit 2310478e authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'add-select-for-update-to-cross-db-modification-check' into 'master'

Check for FOR UPDATE queries

See merge request gitlab-org/gitlab!68863
parents 8131801a 9a5d7703
......@@ -74,7 +74,9 @@ module Database
return if cross_database_context[:transaction_depth_by_db].values.all?(&:zero?)
tables = PgQuery.parse(sql).dml_tables
parsed_query = PgQuery.parse(sql)
tables = sql.downcase.include?(' for update') ? parsed_query.tables : parsed_query.dml_tables
return if tables.empty?
cross_database_context[:modified_tables_by_db][database].merge(tables)
......
......@@ -99,6 +99,25 @@ RSpec.describe 'Database::PreventCrossDatabaseModification' do
end
end
end
context 'when executing a SELECT FOR UPDATE query' do
def run_queries
project.touch
pipeline.lock!
end
context 'outside transaction' do
it { expect { run_queries }.not_to raise_error }
end
context 'when data modification happens in a transaction' do
it 'raises error' do
Project.transaction do
expect { run_queries }.to raise_error /Cross-database data modification/
end
end
end
end
end
context 'when CI association is modified through project' 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