Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da5a566ecf | ||
|
|
38f26f4e8b | ||
|
|
422d1a0acd | ||
|
|
f790dc1872 | ||
|
|
2fcdd56338 | ||
|
|
47f06f40df | ||
|
|
998402e531 | ||
|
|
bd4eeb3f9e | ||
|
|
b9615a912f | ||
|
|
39c071f790 | ||
|
|
e37cdb4ca0 | ||
|
|
c8410541a4 | ||
|
|
55ebc73f9e | ||
|
|
027256dbb7 | ||
|
|
076cacc6f1 | ||
|
|
741d171f4a | ||
|
|
093e0bcb36 | ||
|
|
ca1d5b0c91 | ||
|
|
cd62071757 | ||
|
|
4c15fafd72 | ||
|
|
b246ada312 | ||
|
|
ecf0a06448 | ||
|
|
ec0d94dd0e | ||
|
|
c5bbb180c2 | ||
|
|
9fa532623d | ||
|
|
921800e6a3 | ||
|
|
dfd26d930e | ||
|
|
c0270068c4 | ||
|
|
9010642326 | ||
|
|
8974986d61 | ||
|
|
fea2474117 | ||
|
|
654fa3ac02 | ||
|
|
24cb6cf9c1 | ||
|
|
1c7b0c71ec |
20
.travis.yml
20
.travis.yml
@@ -1,4 +1,3 @@
|
||||
dist: xenial
|
||||
language: c
|
||||
sudo: required
|
||||
|
||||
@@ -7,31 +6,30 @@ env:
|
||||
- PGUSER=postgres
|
||||
- PGDATABASE=postgres
|
||||
- PGOPTIONS='-c client_min_messages=NOTICE'
|
||||
- PGPORT=5432
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- env: POSTGRESQL_VERSION="9.6" POSTGIS_VERSION="2.5"
|
||||
dist: xenial
|
||||
- env: POSTGRESQL_VERSION="10" POSTGIS_VERSION="2.5"
|
||||
dist: xenial
|
||||
- env: POSTGRESQL_VERSION="11" POSTGIS_VERSION="2.5"
|
||||
dist: xenial
|
||||
- env: POSTGRESQL_VERSION="12" POSTGIS_VERSION="2.5"
|
||||
dist: bionic
|
||||
- env: POSTGRESQL_VERSION="12" POSTGIS_VERSION="3"
|
||||
allow_failures:
|
||||
- env: POSTGRESQL_VERSION="12" POSTGIS_VERSION="2.5"
|
||||
- env: POSTGRESQL_VERSION="12" POSTGIS_VERSION="3"
|
||||
dist: bionic
|
||||
|
||||
script:
|
||||
- sudo service postgresql stop;
|
||||
- sudo apt-get remove postgresql* -y
|
||||
- sudo apt-get install -y --allow-unauthenticated --no-install-recommends --no-install-suggests postgresql-$POSTGRESQL_VERSION postgresql-client-$POSTGRESQL_VERSION postgresql-server-dev-$POSTGRESQL_VERSION postgresql-common
|
||||
- if [[ $POSTGRESQL_VERSION == '9.6' ]]; then sudo apt-get install -y postgresql-contrib-9.6; fi;
|
||||
- sudo apt-get install -y --allow-unauthenticated postgresql-$POSTGRESQL_VERSION-postgis-$POSTGIS_VERSION postgresql-$POSTGRESQL_VERSION-postgis-$POSTGIS_VERSION-scripts postgis
|
||||
# For pre12, install plpython2. For PG12 install plpython3
|
||||
- if [[ $POSTGRESQL_VERSION != '12' ]]; then sudo apt-get install -y postgresql-plpython-$POSTGRESQL_VERSION python python-redis; else sudo apt-get install -y postgresql-plpython3-12 python3 python3-redis; fi;
|
||||
- sudo pg_dropcluster --stop $POSTGRESQL_VERSION main
|
||||
- sudo rm -rf /etc/postgresql/$POSTGRESQL_VERSION /var/lib/postgresql/$POSTGRESQL_VERSION
|
||||
- sudo pg_createcluster -u postgres $POSTGRESQL_VERSION main -- --auth-local trust --auth-host password
|
||||
- sudo /etc/init.d/postgresql start $POSTGRESQL_VERSION || sudo journalctl -xe
|
||||
- sudo rm -rf /etc/postgresql/$POSTGRESQL_VERSION /var/lib/postgresql/$POSTGRESQL_VERSION /var/ramfs/postgresql/$POSTGRESQL_VERSION
|
||||
- sudo pg_createcluster -u postgres $POSTGRESQL_VERSION main --start -- --auth-local trust --auth-host password
|
||||
- export PGPORT=$(pg_lsclusters | grep $POSTGRESQL_VERSION | awk '{print $3}')
|
||||
- make
|
||||
- sudo make install
|
||||
- make installcheck
|
||||
@@ -40,3 +38,5 @@ after_failure:
|
||||
- pg_lsclusters
|
||||
- cat regression.out
|
||||
- cat regression.diffs
|
||||
- echo $PGPORT
|
||||
- cat /var/log/postgresql/postgresql-$POSTGRESQL_VERSION-main.log
|
||||
|
||||
15
Makefile
15
Makefile
@@ -1,7 +1,7 @@
|
||||
# cartodb/Makefile
|
||||
|
||||
EXTENSION = cartodb
|
||||
EXTVERSION = 0.33.0
|
||||
EXTVERSION = 0.36.0
|
||||
|
||||
SED = sed
|
||||
AWK = awk
|
||||
@@ -106,6 +106,9 @@ UPGRADABLE = \
|
||||
0.31.0 \
|
||||
0.32.0 \
|
||||
0.33.0 \
|
||||
0.34.0 \
|
||||
0.35.0 \
|
||||
0.36.0 \
|
||||
$(EXTVERSION)dev \
|
||||
$(EXTVERSION)next \
|
||||
$(END)
|
||||
@@ -139,9 +142,7 @@ PG_VERSION := $(shell $(PG_CONFIG) --version | $(AWK) '{split($$2,a,"."); print
|
||||
PG_12_GE := $(shell [ $(PG_VERSION) -ge 12 ] && echo true)
|
||||
PLPYTHONU := plpythonu
|
||||
ifeq ($(PG_12_GE), true)
|
||||
# Reverted until we are ready for PG12 support in other projects
|
||||
PLPYTHONU := plpythonu
|
||||
# PLPYTHONU := plpython3u
|
||||
PLPYTHONU := plpython3u
|
||||
endif
|
||||
PGPORT ?= '5432'
|
||||
PGUSER ?= 'postgres'
|
||||
@@ -151,7 +152,7 @@ $(EXTENSION)--$(EXTVERSION).sql: $(CDBSCRIPTS) cartodb_version.sql Makefile
|
||||
cat $(CDBSCRIPTS) | \
|
||||
$(SED) -e 's/@extschema@/cartodb/g' \
|
||||
-e 's/@postgisschema@/public/g' \
|
||||
-e 's/plpythonu/$(PLPYTHONU)/g' >> $@
|
||||
-e 's/@@plpythonu@@/$(PLPYTHONU)/g' >> $@
|
||||
echo "GRANT USAGE ON SCHEMA cartodb TO public;" >> $@
|
||||
cat cartodb_version.sql >> $@
|
||||
|
||||
@@ -165,10 +166,10 @@ $(EXTENSION)--$(EXTVERSION)--$(EXTVERSION)next.sql: $(EXTENSION)--$(EXTVERSION).
|
||||
cp $< $@
|
||||
|
||||
$(EXTENSION).control: $(EXTENSION).control.in Makefile
|
||||
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/g' -e 's/plpythonu/$(PLPYTHONU)/g' $< > $@
|
||||
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/g' -e 's/@@plpythonu@@/$(PLPYTHONU)/g' $< > $@
|
||||
|
||||
cartodb_version.sql: cartodb_version.sql.in Makefile $(GITDIR)/index
|
||||
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/' -e 's/@extschema@/cartodb/g' -e "s/@postgisschema@/public/g" -e 's/plpythonu/$(PLPYTHONU)/g' $< > $@
|
||||
$(SED) -e 's/@@VERSION@@/$(EXTVERSION)/' -e 's/@extschema@/cartodb/g' -e "s/@postgisschema@/public/g" -e 's/@@plpythonu@@/$(PLPYTHONU)/g' $< > $@
|
||||
|
||||
# Needed for consistent `echo` results with backslashes
|
||||
SHELL = bash
|
||||
|
||||
12
NEWS.md
12
NEWS.md
@@ -1,3 +1,15 @@
|
||||
0.36.0 (2020-02-13)
|
||||
* Make `_CDB_Group_API_Auth` python3 compatible by passing bytes representation instead of a string.
|
||||
* Make `_CDB_Group_API_Request` python3 compatible by adapting the function signature of `HTTPConnection`.
|
||||
|
||||
0.35.0 (2019-12-30)
|
||||
* Reapply the changes in 0.33.0 (the issue we were looking for was unrelated)
|
||||
* Reapply `Make PG12 depend on plpython3u instead of plpythonu`
|
||||
* Fix identifier quotation in `CDB_UserDataSize`
|
||||
|
||||
0.34.0 (2019-12-23)
|
||||
* Revert changes done in 0.33.0, keeping function signature to drop them
|
||||
|
||||
0.33.0 (2019-12-20)
|
||||
* Revert `Make PG12 depend on plpython3u instead of plpythonu`.
|
||||
* Add functions to manage Federated Tables (Foreign Data Wrapper)
|
||||
|
||||
@@ -3,4 +3,4 @@ comment = 'Turn a database into a cartodb user database.'
|
||||
superuser = true
|
||||
relocatable = false
|
||||
schema = cartodb
|
||||
requires = 'plpythonu, postgis'
|
||||
requires = '@@plpythonu@@, postgis'
|
||||
|
||||
@@ -65,7 +65,7 @@ $$
|
||||
LANGUAGE SQL IMMUTABLE PARALLEL SAFE;
|
||||
|
||||
--
|
||||
-- Produce a valid name for a schema generated for the Federated Server
|
||||
-- Produce a valid name for a schema generated for the Federated Server
|
||||
--
|
||||
CREATE OR REPLACE FUNCTION @extschema@.__CDB_FS_Generate_Schema_Name(internal_server_name NAME, schema_name TEXT)
|
||||
RETURNS NAME
|
||||
@@ -155,7 +155,7 @@ BEGIN
|
||||
IF NOT (input_config ? 'credentials') THEN
|
||||
RAISE EXCEPTION 'Credentials are mandatory';
|
||||
END IF;
|
||||
|
||||
|
||||
-- For now, allow not passing username or password
|
||||
IF input_config->'credentials'->'username' IS NOT NULL THEN
|
||||
mapping := jsonb_build_object('user', input_config->'credentials'->'username');
|
||||
@@ -163,7 +163,7 @@ BEGIN
|
||||
IF input_config->'credentials'->'password' IS NOT NULL THEN
|
||||
mapping := mapping || jsonb_build_object('password', input_config->'credentials'->'password');
|
||||
END IF;
|
||||
|
||||
|
||||
RETURN (input_config - 'credentials')::jsonb || jsonb_build_object('user_mapping', mapping);
|
||||
END
|
||||
$$
|
||||
@@ -345,7 +345,7 @@ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;
|
||||
|
||||
--
|
||||
-- List registered servers
|
||||
--
|
||||
--
|
||||
CREATE OR REPLACE FUNCTION @extschema@.CDB_Federated_Server_List_Servers(server TEXT DEFAULT '%')
|
||||
RETURNS TABLE (
|
||||
name text,
|
||||
|
||||
@@ -191,7 +191,7 @@ AS $$
|
||||
})
|
||||
return json.dumps(stats)
|
||||
$$
|
||||
LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE;
|
||||
LANGUAGE @@plpythonu@@ VOLATILE PARALLEL UNSAFE;
|
||||
|
||||
|
||||
--
|
||||
|
||||
@@ -244,7 +244,7 @@ BEGIN
|
||||
EXCEPTION WHEN OTHERS THEN
|
||||
RAISE EXCEPTION 'Could not import schema "%" of server "%": %', remote_schema, server, SQLERRM;
|
||||
END;
|
||||
|
||||
|
||||
BEGIN
|
||||
src_table := format('%I.%I', local_schema, remote_table);
|
||||
EXCEPTION WHEN OTHERS THEN
|
||||
|
||||
@@ -32,7 +32,6 @@ AS $$
|
||||
client = redis.Redis(host=tis_host, port=tis_port, socket_timeout=tis_timeout)
|
||||
GD['invalidation'] = client
|
||||
except Exception as err:
|
||||
error = "client_error - %s" % str(err)
|
||||
# NOTE: no retries on connection error
|
||||
plpy.warning('Error trying to connect to Invalidation Service to link Ghost Tables: ' + str(err))
|
||||
break
|
||||
@@ -41,13 +40,12 @@ AS $$
|
||||
client.execute_command('DBSCH', db_name, username, event_name)
|
||||
break
|
||||
except Exception as err:
|
||||
error = "request_error - %s" % str(err)
|
||||
client = GD['invalidation'] = None # force reconnect
|
||||
if not tis_retry:
|
||||
plpy.warning('Error calling Invalidation Service to link Ghost Tables: ' + str(err))
|
||||
break
|
||||
tis_retry -= 1 # try reconnecting
|
||||
$$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE;
|
||||
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
|
||||
|
||||
-- Enqueues a job to run Ghost tables linking process for the current user
|
||||
CREATE OR REPLACE FUNCTION @extschema@.CDB_LinkGhostTables(event_name text DEFAULT 'USER')
|
||||
@@ -61,7 +59,7 @@ AS $$
|
||||
EXECUTE 'SELECT current_database();' INTO db_name;
|
||||
|
||||
PERFORM @extschema@._CDB_LinkGhostTables(username, db_name, event_name);
|
||||
RAISE NOTICE '_CDB_LinkGhostTables() called with username=%, event_name=%', username, event_name;
|
||||
RAISE INFO '_CDB_LinkGhostTables() called with username=%, event_name=%', username, event_name;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql
|
||||
VOLATILE
|
||||
|
||||
@@ -21,7 +21,7 @@ $$
|
||||
body = '{ "name": "%s", "database_role": "%s" }' % (group_name, group_role)
|
||||
query = "select @extschema@._CDB_Group_API_Request('POST', '%s', '%s', '{200, 409}') as response_status" % (url, body)
|
||||
plpy.execute(query)
|
||||
$$ LANGUAGE 'plpythonu'
|
||||
$$ LANGUAGE '@@plpythonu@@'
|
||||
VOLATILE
|
||||
PARALLEL UNSAFE
|
||||
SECURITY DEFINER
|
||||
@@ -41,7 +41,7 @@ $$
|
||||
|
||||
query = "select @extschema@._CDB_Group_API_Request('DELETE', '%s', '', '{204, 404}') as response_status" % url
|
||||
plpy.execute(query)
|
||||
$$ LANGUAGE 'plpythonu'
|
||||
$$ LANGUAGE '@@plpythonu@@'
|
||||
VOLATILE
|
||||
PARALLEL UNSAFE
|
||||
SECURITY DEFINER
|
||||
@@ -61,7 +61,7 @@ $$
|
||||
body = '{ "name": "%s", "database_role": "%s" }' % (new_group_name, new_group_role)
|
||||
query = "select @extschema@._CDB_Group_API_Request('PUT', '%s', '%s', '{200, 409}') as response_status" % (url, body)
|
||||
plpy.execute(query)
|
||||
$$ LANGUAGE 'plpythonu'
|
||||
$$ LANGUAGE '@@plpythonu@@'
|
||||
VOLATILE
|
||||
PARALLEL UNSAFE
|
||||
SECURITY DEFINER
|
||||
@@ -81,7 +81,7 @@ $$
|
||||
body = "{ \"users\": [\"%s\"] }" % "\",\"".join(usernames)
|
||||
query = "select @extschema@._CDB_Group_API_Request('POST', '%s', '%s', '{200, 409}') as response_status" % (url, body)
|
||||
plpy.execute(query)
|
||||
$$ LANGUAGE 'plpythonu'
|
||||
$$ LANGUAGE '@@plpythonu@@'
|
||||
VOLATILE
|
||||
PARALLEL UNSAFE
|
||||
SECURITY DEFINER
|
||||
@@ -101,7 +101,7 @@ $$
|
||||
body = "{ \"users\": [\"%s\"] }" % "\",\"".join(usernames)
|
||||
query = "select @extschema@._CDB_Group_API_Request('DELETE', '%s', '%s', '{200, 404}') as response_status" % (url, body)
|
||||
plpy.execute(query)
|
||||
$$ LANGUAGE 'plpythonu'
|
||||
$$ LANGUAGE '@@plpythonu@@'
|
||||
VOLATILE
|
||||
PARALLEL UNSAFE
|
||||
SECURITY DEFINER
|
||||
@@ -129,7 +129,7 @@ $$
|
||||
body = '{ "access": "%s" }' % access
|
||||
query = "select @extschema@._CDB_Group_API_Request('PUT', '%s', '%s', '{200, 409}') as response_status" % (url, body)
|
||||
plpy.execute(query)
|
||||
$$ LANGUAGE 'plpythonu'
|
||||
$$ LANGUAGE '@@plpythonu@@'
|
||||
VOLATILE
|
||||
PARALLEL UNSAFE
|
||||
SECURITY DEFINER
|
||||
@@ -156,7 +156,7 @@ $$
|
||||
url = '/api/v1/databases/{0}/groups/%s/permission/%s/tables/%s' % (pathname2url(group_name), username, table_name)
|
||||
query = "select @extschema@._CDB_Group_API_Request('DELETE', '%s', '', '{200, 404}') as response_status" % url
|
||||
plpy.execute(query)
|
||||
$$ LANGUAGE 'plpythonu'
|
||||
$$ LANGUAGE '@@plpythonu@@'
|
||||
VOLATILE
|
||||
PARALLEL UNSAFE
|
||||
SECURITY DEFINER
|
||||
@@ -191,25 +191,36 @@ $$
|
||||
params = json.loads(conf)
|
||||
auth = 'Basic %s' % plpy.execute("SELECT @extschema@._CDB_Group_API_Auth('%s', '%s') as auth" % (params['username'], params['password']))[0]['auth']
|
||||
return { "host": params['host'], "port": params['port'], 'timeout': params['timeout'], 'auth': auth }
|
||||
$$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE;
|
||||
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
|
||||
|
||||
CREATE OR REPLACE
|
||||
FUNCTION @extschema@._CDB_Group_API_Auth(username text, password text)
|
||||
RETURNS TEXT AS
|
||||
$$
|
||||
import sys
|
||||
import base64
|
||||
return base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
|
||||
$$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE;
|
||||
|
||||
data_to_encode = '%s:%s' % (username, password)
|
||||
if sys.version_info[0] < 3:
|
||||
data_encoded = base64.encodestring(data_to_encode)
|
||||
else:
|
||||
data_encoded = base64.b64encode(data_to_encode.encode()).decode()
|
||||
|
||||
data_encoded = data_encoded.replace('\n', '')
|
||||
return data_encoded
|
||||
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
|
||||
|
||||
-- url must contain a '%s' placeholder that will be replaced by current_database, for security reasons.
|
||||
CREATE OR REPLACE
|
||||
FUNCTION @extschema@._CDB_Group_API_Request(method text, url text, body text, valid_return_codes int[])
|
||||
RETURNS int AS
|
||||
$$
|
||||
python_v2 = True
|
||||
try:
|
||||
import httplib as client
|
||||
import httplib as client
|
||||
except:
|
||||
from http import client
|
||||
from http import client
|
||||
python_v2 = False
|
||||
|
||||
params = plpy.execute("select c.host, c.port, c.timeout, c.auth from @extschema@._CDB_Group_API_Conf() c;")[0]
|
||||
if params['host'] is None:
|
||||
@@ -222,7 +233,10 @@ $$
|
||||
last_err = None
|
||||
while retry > 0:
|
||||
try:
|
||||
conn = SD['groups_api_client'] = client.HTTPConnection(params['host'], params['port'], False, params['timeout'])
|
||||
if python_v2:
|
||||
conn = SD['groups_api_client'] = client.HTTPConnection(params['host'], params['port'], False, params['timeout'])
|
||||
else:
|
||||
conn = SD['groups_api_client'] = client.HTTPConnection(params['host'], port=params['port'], timeout=params['timeout'])
|
||||
database_name = plpy.execute("select current_database();")[0]['current_database']
|
||||
conn.request(method, url.format(database_name), body, headers)
|
||||
response = conn.getresponse()
|
||||
@@ -239,5 +253,5 @@ $$
|
||||
raise last_err
|
||||
|
||||
return None
|
||||
$$ LANGUAGE 'plpythonu' VOLATILE PARALLEL UNSAFE;
|
||||
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
|
||||
revoke all on function @extschema@._CDB_Group_API_Request(text, text, text, int[]) from public;
|
||||
|
||||
@@ -6,6 +6,13 @@ AS $$
|
||||
$$
|
||||
LANGUAGE SQL STABLE PARALLEL SAFE;
|
||||
|
||||
|
||||
----- ########################## WARNING ##########################
|
||||
----- The code below creates a new role for the organization but
|
||||
----- only when the extension is INSTALLED in a database, i.e. it
|
||||
----- won't work if you clone a database that has it installed.
|
||||
----- If you do, you need to update the extension to next and back
|
||||
----- ########################## WARNING ##########################
|
||||
DO LANGUAGE 'plpgsql' $$
|
||||
DECLARE
|
||||
cdb_org_member_role_name TEXT;
|
||||
@@ -38,6 +45,12 @@ AS $$
|
||||
$$
|
||||
LANGUAGE SQL STABLE PARALLEL SAFE;
|
||||
|
||||
----- ########################## WARNING ##########################
|
||||
----- The code below creates a new role for the organization but
|
||||
----- only when the extension is INSTALLED in a database, i.e. it
|
||||
----- won't work if you clone a database that has it installed.
|
||||
----- If you do, you need to update the extension to next and back
|
||||
----- ########################## WARNING ##########################
|
||||
-- Administrator role creation on extension install
|
||||
DO LANGUAGE 'plpgsql' $$
|
||||
DECLARE
|
||||
|
||||
@@ -11,4 +11,4 @@ RETURNS SETOF TEXT AS $$
|
||||
cleaned = match[0].strip()
|
||||
if ( cleaned ):
|
||||
yield cleaned
|
||||
$$ language 'plpythonu' IMMUTABLE STRICT PARALLEL SAFE;
|
||||
$$ language '@@plpythonu@@' IMMUTABLE STRICT PARALLEL SAFE;
|
||||
|
||||
@@ -33,7 +33,7 @@ BEGIN
|
||||
|
||||
IF raster_available THEN
|
||||
raster_read_query := Format('SELECT o_table_name, r_table_name FROM @postgisschema@.raster_overviews
|
||||
WHERE o_table_schema = ''%I'' AND o_table_catalog = current_database()', schema_name);
|
||||
WHERE o_table_schema = %L AND o_table_catalog = current_database()', schema_name);
|
||||
ELSE
|
||||
raster_read_query := 'SELECT NULL::text AS o_table_name, NULL::text AS r_table_name';
|
||||
END IF;
|
||||
@@ -42,7 +42,7 @@ BEGIN
|
||||
%s
|
||||
),
|
||||
user_tables AS (
|
||||
SELECT table_name FROM @extschema@._CDB_NonAnalysisTablesInSchema(''%I'')
|
||||
SELECT table_name FROM @extschema@._CDB_NonAnalysisTablesInSchema(%L)
|
||||
),
|
||||
table_cat AS (
|
||||
SELECT
|
||||
@@ -55,7 +55,7 @@ BEGIN
|
||||
FROM user_tables
|
||||
),
|
||||
sizes AS (
|
||||
SELECT COALESCE(INT8(SUM(@extschema@._CDB_total_relation_size(''%I'', table_name)))) table_size,
|
||||
SELECT COALESCE(INT8(SUM(@extschema@._CDB_total_relation_size(%L, table_name)))) table_size,
|
||||
CASE
|
||||
WHEN is_overview THEN 0
|
||||
WHEN is_raster THEN 1
|
||||
|
||||
@@ -99,11 +99,12 @@ FROM latency;
|
||||
\echo '%% It raises an error if the wrong port is provided'
|
||||
SELECT '3.0', cartodb.CDB_Federated_Server_Diagnostics(server => 'wrong-port');
|
||||
|
||||
\echo '%% Latency stats: can get them on default PG port 5432 when not provided'
|
||||
WITH latency AS (
|
||||
SELECT CDB_Federated_Server_Diagnostics('loopback-no-port')->'server_latency_ms' ms
|
||||
) SELECT '2.4', 0.0 <= (latency.ms->'min')::text::float, (latency.ms->'max')::text::float <= 1000.0
|
||||
FROM latency;
|
||||
-- Disabled: It's not compatible with Travis since the target database (self) might be in a different port
|
||||
-- \echo '%% Latency stats: can get them on default PG port 5432 when not provided'
|
||||
-- WITH latency AS (
|
||||
-- SELECT CDB_Federated_Server_Diagnostics('loopback-no-port')->'server_latency_ms' ms
|
||||
-- ) SELECT '2.4', 0.0 <= (latency.ms->'min')::text::float, (latency.ms->'max')::text::float <= 1000.0
|
||||
-- FROM latency;
|
||||
|
||||
|
||||
-- ===================================================================
|
||||
|
||||
@@ -21,8 +21,6 @@ ERROR: Server "doesNotExist" does not exist
|
||||
2.3|t
|
||||
%% It raises an error if the wrong port is provided
|
||||
ERROR: could not connect to server "cdb_fs_wrong-port"
|
||||
%% Latency stats: can get them on default PG port 5432 when not provided
|
||||
2.4|t|t
|
||||
D1|
|
||||
D2|
|
||||
D3|
|
||||
|
||||
@@ -2,20 +2,20 @@
|
||||
## List non-existent server shows nothing
|
||||
## Create and list a server works
|
||||
1.3|
|
||||
1.4|(myRemote,postgres_fdw,localhost,5432,,read-only,fdw_user)
|
||||
1.4|(myRemote,postgres_fdw,localhost,@@PGPORT@@,,read-only,fdw_user)
|
||||
## Create and list a second server works
|
||||
2.1|
|
||||
2.2|(myRemote,postgres_fdw,localhost,5432,,read-only,fdw_user)
|
||||
2.2|(myRemote2,postgres_fdw,localhost,5432,fdw_target,read-only,fdw_user)
|
||||
2.2|(myRemote,postgres_fdw,localhost,@@PGPORT@@,,read-only,fdw_user)
|
||||
2.2|(myRemote2,postgres_fdw,localhost,@@PGPORT@@,fdw_target,read-only,fdw_user)
|
||||
## List server by name works
|
||||
2.3|(myRemote,postgres_fdw,localhost,5432,,read-only,fdw_user)
|
||||
2.3|(myRemote,postgres_fdw,localhost,@@PGPORT@@,,read-only,fdw_user)
|
||||
## Re-register a second server works
|
||||
3.1|
|
||||
3.2|(myRemote,postgres_fdw,localhost,5432,,read-only,fdw_user)
|
||||
3.2|(myRemote2,postgres_fdw,localhost,5432,fdw_target,read-only,other_remote_user)
|
||||
3.2|(myRemote,postgres_fdw,localhost,@@PGPORT@@,,read-only,fdw_user)
|
||||
3.2|(myRemote2,postgres_fdw,localhost,@@PGPORT@@,fdw_target,read-only,other_remote_user)
|
||||
## Unregister server 1 works
|
||||
4.1|
|
||||
4.2|(myRemote2,postgres_fdw,localhost,5432,fdw_target,read-only,other_remote_user)
|
||||
4.2|(myRemote2,postgres_fdw,localhost,@@PGPORT@@,fdw_target,read-only,other_remote_user)
|
||||
## Unregistering a server that does not exist fails
|
||||
ERROR: Server "doesNotExist" does not exist
|
||||
## Unregister the second server works
|
||||
@@ -30,25 +30,25 @@ ERROR: Server information is mandatory
|
||||
ERROR: Credentials are mandatory
|
||||
## Create a server with empty credentials works
|
||||
7.3|
|
||||
7.4|(empty,postgres_fdw,localhost,5432,fdw_target,read-only,)
|
||||
7.4|(empty,postgres_fdw,localhost,@@PGPORT@@,fdw_target,read-only,)
|
||||
7.5|
|
||||
## Create a server without options fails
|
||||
ERROR: Server information is mandatory
|
||||
## Create a server with special characters works
|
||||
8.1|
|
||||
8.2|("myRemote"" or'not",postgres_fdw,localhost,5432,"fdw target",read-only,"fdw user")
|
||||
8.2|("myRemote"" or'not",postgres_fdw,localhost,@@PGPORT@@,"fdw target",read-only,"fdw user")
|
||||
8.3|
|
||||
9.1|
|
||||
You are now connected to database "contrib_regression" as user "cdb_fs_tester".
|
||||
## All users are able to list servers
|
||||
9.2|(myRemote3,postgres_fdw,localhost,5432,,read-only,)
|
||||
9.2|(myRemote3,postgres_fdw,localhost,@@PGPORT@@,,read-only,)
|
||||
## Only superadmins can create servers
|
||||
ERROR: Could not create server myRemote4: permission denied for foreign-data wrapper postgres_fdw
|
||||
You are now connected to database "contrib_regression" as user "postgres".
|
||||
## Granting access to a user works
|
||||
9.5|
|
||||
You are now connected to database "contrib_regression" as user "cdb_fs_tester".
|
||||
9.55|(myRemote3,postgres_fdw,localhost,5432,,read-only,fdw_user)
|
||||
9.55|(myRemote3,postgres_fdw,localhost,@@PGPORT@@,,read-only,fdw_user)
|
||||
You are now connected to database "contrib_regression" as user "postgres".
|
||||
ERROR: Server "does not exist" does not exist
|
||||
ERROR: Could not grant access on "myRemote3" to "does not exist": role "does not exist" does not exist
|
||||
|
||||
@@ -1,6 +1,56 @@
|
||||
-- Create user and enable Ghost tables trigger
|
||||
\set QUIET on
|
||||
SET client_min_messages TO error;
|
||||
|
||||
-- Recreate the function without extra error messages as it changes depending on the python-redis version
|
||||
CREATE OR REPLACE FUNCTION cartodb._CDB_LinkGhostTables(username text, db_name text, event_name text)
|
||||
RETURNS void
|
||||
AS $$
|
||||
if not username:
|
||||
return
|
||||
|
||||
if 'json' not in GD:
|
||||
import json
|
||||
GD['json'] = json
|
||||
else:
|
||||
json = GD['json']
|
||||
|
||||
tis_config = plpy.execute("select cartodb.CDB_Conf_GetConf('invalidation_service');")[0]['cdb_conf_getconf']
|
||||
if not tis_config:
|
||||
plpy.warning('Invalidation service configuration not found. Skipping Ghost Tables linking.')
|
||||
return
|
||||
|
||||
tis_config_dict = json.loads(tis_config)
|
||||
tis_host = tis_config_dict.get('host')
|
||||
tis_port = tis_config_dict.get('port')
|
||||
tis_timeout = tis_config_dict.get('timeout', 5)
|
||||
tis_retry = tis_config_dict.get('retry', 5)
|
||||
|
||||
client = GD.get('invalidation', None)
|
||||
|
||||
while True:
|
||||
|
||||
if not client:
|
||||
try:
|
||||
import redis
|
||||
client = redis.Redis(host=tis_host, port=tis_port, socket_timeout=tis_timeout)
|
||||
GD['invalidation'] = client
|
||||
except Exception as err:
|
||||
# NOTE: no retries on connection error
|
||||
plpy.warning('Error trying to connect to Invalidation Service to link Ghost Tables')
|
||||
break
|
||||
|
||||
try:
|
||||
client.execute_command('DBSCH', db_name, username, event_name)
|
||||
break
|
||||
except Exception as err:
|
||||
client = GD['invalidation'] = None # force reconnect
|
||||
if not tis_retry:
|
||||
plpy.warning('Error calling Invalidation Service to link Ghost Tables')
|
||||
break
|
||||
tis_retry -= 1 # try reconnecting
|
||||
$$ LANGUAGE '@@plpythonu@@' VOLATILE PARALLEL UNSAFE;
|
||||
|
||||
SELECT CDB_EnableGhostTablesTrigger();
|
||||
CREATE ROLE "fulano" LOGIN;
|
||||
GRANT ALL ON SCHEMA cartodb TO "fulano";
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
|
||||
|
||||
WARNING: Invalidation service configuration not found. Skipping Ghost Tables linking.
|
||||
NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
|
||||
INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
|
||||
|
||||
|
||||
WARNING: Error calling Invalidation Service to link Ghost Tables: Error -2 connecting to fake-tis-host:3142. Name or service not known.
|
||||
NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
|
||||
WARNING: Error calling Invalidation Service to link Ghost Tables
|
||||
INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=USER
|
||||
|
||||
BEGIN
|
||||
cdb_ddl_execution
|
||||
0
|
||||
CREATE TABLE
|
||||
1
|
||||
WARNING: Error calling Invalidation Service to link Ghost Tables: Error -2 connecting to fake-tis-host:3142. Name or service not known.
|
||||
NOTICE: _CDB_LinkGhostTables() called with username=fulanito, event_name=CREATE TABLE
|
||||
WARNING: Error calling Invalidation Service to link Ghost Tables
|
||||
INFO: _CDB_LinkGhostTables() called with username=fulanito, event_name=CREATE TABLE
|
||||
COMMIT
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,9 @@ SELECT 'excess3', catch_error($$INSERT INTO big VALUES (3);$$); -- disallowed, q
|
||||
DROP TABLE big;
|
||||
SELECT CDB_SetUserQuotaInBytes(0);
|
||||
|
||||
CREATE SCHEMA "complex-name%_with'quotes""";
|
||||
SELECT CDB_UserDataSize('"complex-name%_with''quotes"');
|
||||
DROP SCHEMA "complex-name%_with'quotes""";
|
||||
|
||||
set client_min_messages to NOTICE;
|
||||
DROP FUNCTION catch_error(text);
|
||||
|
||||
@@ -30,6 +30,9 @@ DROP TABLE
|
||||
excess3|t
|
||||
DROP TABLE
|
||||
0
|
||||
CREATE SCHEMA
|
||||
0
|
||||
DROP SCHEMA
|
||||
SET
|
||||
DROP FUNCTION
|
||||
DROP FUNCTION
|
||||
|
||||
Reference in New Issue
Block a user