Skip to content
Snippets Groups Projects
Verified Commit 9d09bab7 authored by Omar Qunsul's avatar Omar Qunsul 2️⃣
Browse files

Identifying all cross joins between namespaces and users

Addressing Issue #415196

Changelog: other
parent 1b9172f7
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ allow_cross_joins:
- gitlab_main
# Temporarily allow cross-joins between clusterwide and cell schemas
# This is to be removed once we annotate all cross-joins between those
- gitlab_main_clusterwide
# - gitlab_main_clusterwide temporarily disabling this to discover all the cross-join violations
allow_cross_transactions:
- gitlab_internal
- gitlab_shared
......
......@@ -43,6 +43,25 @@ def self.validate_cross_joins!(sql)
unless ::Gitlab::Database::GitlabSchema.cross_joins_allowed?(schemas)
Thread.current[:has_cross_join_exception] = true
if (%w[users namespaces] - tables).empty?
open('rspec/cross_join_errors.txt', 'a') do |file| # this file will be in the tests artifacts
app_backtrace = caller.grep(/\/app\//)
spec_backtrace = caller.grep(/\_spec.rb/)
line = sql.match(/line:([^\*]+)/)[1]
# Hashing the item to deduplicate them
md5 = Digest::MD5.new
md5.update line # we can use another elements later for deduplication of items
hash = md5.hexdigest
item = {
hash: hash,
query: sql,
line: line,
app_backtrace: app_backtrace,
spec_backtrace: spec_backtrace
}
file.puts(item.to_json)
end
end
raise CrossJoinAcrossUnsupportedTablesError,
"Unsupported cross-join across '#{tables.join(", ")}' querying '#{schemas.to_a.join(", ")}' discovered " \
"when executing query '#{sql}'. Please refer to https://docs.gitlab.com/ee/development/database/multiple_databases.html#removing-joins-between-ci_-and-non-ci_-tables for details on how to resolve this exception."
......
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