summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2019-02-12 13:09:32 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2019-02-12 13:09:32 +0000
commit1319a9edd901751fe58daeb2f5f2f31b09290d99 (patch)
treeef2a3a2b37a7310bbd3c132c0816bb5ccd7a9345
parent937255196c821a8e28a1a87eb4eaf8ec05783ca7 (diff)
parent9100ca188c45f2129d5e891534ed38718ef67e46 (diff)
downloadgitlab-ce-1319a9edd901751fe58daeb2f5f2f31b09290d99.tar.gz
Merge branch '8798-geo-implement-selective-sync-support-for-the-various-fdw-queries' into 'master'
Replace dots with an underscore when creating an alias for the recursive CTE See merge request gitlab-org/gitlab-ce!25112
-rw-r--r--lib/gitlab/sql/recursive_cte.rb2
-rw-r--r--spec/lib/gitlab/sql/recursive_cte_spec.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/gitlab/sql/recursive_cte.rb b/lib/gitlab/sql/recursive_cte.rb
index ec1f00a3a91..e45ac5d4765 100644
--- a/lib/gitlab/sql/recursive_cte.rb
+++ b/lib/gitlab/sql/recursive_cte.rb
@@ -48,7 +48,7 @@ module Gitlab
#
# alias_table - The Arel table to use as the alias.
def alias_to(alias_table)
- Arel::Nodes::As.new(table, alias_table)
+ Arel::Nodes::As.new(table, Arel::Table.new(alias_table.name.tr('.', '_')))
end
# Applies the CTE to the given relation, returning a new one that will
diff --git a/spec/lib/gitlab/sql/recursive_cte_spec.rb b/spec/lib/gitlab/sql/recursive_cte_spec.rb
index 25146860615..7fe39dd5a96 100644
--- a/spec/lib/gitlab/sql/recursive_cte_spec.rb
+++ b/spec/lib/gitlab/sql/recursive_cte_spec.rb
@@ -31,6 +31,15 @@ describe Gitlab::SQL::RecursiveCTE, :postgresql do
expect(cte.alias_to(table).to_sql).to eq("#{source_name} AS #{alias_name}")
end
+
+ it 'replaces dots with an underscore' do
+ table = Arel::Table.new('gitlab.kittens')
+
+ source_name = ActiveRecord::Base.connection.quote_table_name(:cte_name)
+ alias_name = ActiveRecord::Base.connection.quote_table_name(:gitlab_kittens)
+
+ expect(cte.alias_to(table).to_sql).to eq("#{source_name} AS #{alias_name}")
+ end
end
describe '#apply_to' do