From 3c586caba4eab9f8061678115435c6f21b3287c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Tue, 12 Nov 2019 13:10:35 +0100 Subject: [PATCH] Qualify calls to cartodb extension so having it in the search_path isn't necessary --- NEWS.md | 1 + lib/backends/dataview.js | 2 +- lib/backends/overviews-metadata.js | 6 +++--- lib/server-options.js | 4 ++-- lib/utils/query-utils.js | 2 +- test/support/sql/windshaft.test.sql | 7 +++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/NEWS.md b/NEWS.md index b4c1dd42..ba5096d1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,7 @@ Announcements: - Be able to set a coherent TTL in Cache-Control header to expire all resources belonging to a map simultaneously. - When `cache buster` in request path is `0` set header `Last-Modified` to now, it avoids stalled content in 3rd party cache providers when they add `If-Modified-Since` header into the request. - Adding a logger to MapStore (#1134) +- Qualify calls to cartodb extension so having it in the search_path isn't necessary. ## 7.2.0 Released 2019-09-30 diff --git a/lib/backends/dataview.js b/lib/backends/dataview.js index 86ead292..d37e3d56 100644 --- a/lib/backends/dataview.js +++ b/lib/backends/dataview.js @@ -8,7 +8,7 @@ var DataviewFactoryWithOverviews = require('../models/dataview/overviews/factory const dbParamsFromReqParams = require('../utils/database-params'); var OverviewsQueryRewriter = require('../utils/overviews-query-rewriter'); var overviewsQueryRewriter = new OverviewsQueryRewriter({ - zoom_level: 'CDB_ZoomFromScale(!scale_denominator!)' + zoom_level: 'cartodb.CDB_ZoomFromScale(!scale_denominator!)' }); var dot = require('dot'); diff --git a/lib/backends/overviews-metadata.js b/lib/backends/overviews-metadata.js index f066c4ef..8b7f0122 100644 --- a/lib/backends/overviews-metadata.js +++ b/lib/backends/overviews-metadata.js @@ -12,9 +12,9 @@ OverviewsMetadataBackend.prototype.getOverviewsMetadata = function (username, sq // FIXME: Currently using internal function _cdb_schema_name // CDB_Overviews should provide the schema information directly. const query = ` - SELECT *, _cdb_schema_name(base_table) - FROM CDB_Overviews( - CDB_QueryTablesText($windshaft$${queryUtils.substituteDummyTokens(sql)}$windshaft$) + SELECT *, cartodb._cdb_schema_name(base_table) + FROM cartodb.CDB_Overviews( + cartodb.CDB_QueryTablesText($windshaft$${queryUtils.substituteDummyTokens(sql)}$windshaft$) ); `; this.pgQueryRunner.run(username, query, function handleOverviewsRows(err, rows) { diff --git a/lib/server-options.js b/lib/server-options.js index ff011bac..dd138419 100644 --- a/lib/server-options.js +++ b/lib/server-options.js @@ -31,11 +31,11 @@ var rendererConfig = _.defaults(global.environment.renderer || {}, { }); rendererConfig.mapnik.queryRewriter = new OverviewsQueryRewriter({ - zoom_level: 'CDB_ZoomFromScale(!scale_denominator!)' + zoom_level: 'cartodb.CDB_ZoomFromScale(!scale_denominator!)' }); rendererConfig.mvt.queryRewriter = new OverviewsQueryRewriter({ - zoom_level: 'CDB_ZoomFromScale(!scale_denominator!)' + zoom_level: 'cartodb.CDB_ZoomFromScale(!scale_denominator!)' }); // Perform keyword substitution in statsd diff --git a/lib/utils/query-utils.js b/lib/utils/query-utils.js index bc7c0307..bd5a4a76 100644 --- a/lib/utils/query-utils.js +++ b/lib/utils/query-utils.js @@ -8,7 +8,7 @@ module.exports.getQueryActualRowCount = function (query) { }; function getQueryRowEstimation(query) { - return 'select CDB_EstimateRowCount($windshaft$' + substituteDummyTokens(query) + '$windshaft$) as rows'; + return 'select cartodb.CDB_EstimateRowCount($windshaft$' + substituteDummyTokens(query) + '$windshaft$) as rows'; } module.exports.getQueryRowEstimation = getQueryRowEstimation; diff --git a/test/support/sql/windshaft.test.sql b/test/support/sql/windshaft.test.sql index d1bf16eb..e336ffce 100644 --- a/test/support/sql/windshaft.test.sql +++ b/test/support/sql/windshaft.test.sql @@ -18,14 +18,13 @@ SET default_with_oids = false; -- public user role DROP USER IF EXISTS :PUBLICUSER; CREATE USER :PUBLICUSER WITH PASSWORD ':PUBLICPASS'; -GRANT USAGE ON SCHEMA cartodb TO :PUBLICUSER; -GRANT ALL ON CDB_TableMetadata TO :PUBLICUSER; +SELECT current_setting('search_path') AS my_path \gset +ALTER ROLE :PUBLICUSER SET search_path = :my_path, cartodb; -- db owner role DROP USER IF EXISTS :TESTUSER; CREATE USER :TESTUSER WITH PASSWORD ':TESTPASS'; -GRANT USAGE ON SCHEMA cartodb TO :TESTUSER; -GRANT ALL ON CDB_TableMetadata TO :TESTUSER; +ALTER ROLE :TESTUSER SET search_path = :my_path, cartodb; -- regular user role 1 DROP USER IF EXISTS test_windshaft_regular1;