cartodb-postgresql/test/CDB_GhostTables.sql

44 lines
1.6 KiB
MySQL
Raw Normal View History

2019-03-07 01:19:38 +08:00
-- Create user and enable Ghost tables trigger
\set QUIET on
2019-03-08 16:18:46 +08:00
SET client_min_messages TO error;
SELECT CDB_EnableGhostTablesTrigger();
2019-03-08 15:28:06 +08:00
CREATE ROLE "fulano" LOGIN;
GRANT ALL ON SCHEMA cartodb TO "fulano";
GRANT SELECT ON cartodb.cdb_ddl_execution TO "fulano";
GRANT EXECUTE ON FUNCTION CDB_Username() TO "fulano";
GRANT EXECUTE ON FUNCTION CDB_LinkGhostTables(text) TO "fulano";
2019-03-08 15:28:06 +08:00
INSERT INTO cdb_conf (key, value) VALUES ('api_keys_fulano', '{"username": "fulanito", "permissions":[]}');
2019-03-08 19:03:55 +08:00
INSERT INTO cdb_conf (key, value) VALUES ('invalidation_service', '{"host": "fake-tis-host"}');
2019-03-08 15:28:06 +08:00
SET SESSION AUTHORIZATION "fulano";
2019-03-08 16:18:46 +08:00
SET client_min_messages TO notice;
2019-03-07 01:19:38 +08:00
\set QUIET off
SELECT CDB_LinkGhostTables(); -- _CDB_LinkGhostTables called
BEGIN;
SELECT to_regclass('cartodb.cdb_ddl_execution'); -- exists
2019-03-07 01:19:38 +08:00
SELECT COUNT(*) FROM cartodb.cdb_ddl_execution; -- 0
2019-03-08 15:28:06 +08:00
CREATE TABLE tmp(id INT);
2019-03-07 01:19:38 +08:00
SELECT COUNT(*) FROM cartodb.cdb_ddl_execution; -- 1
END; -- _CDB_LinkGhostTables called
-- Disable Ghost tables trigger
\set QUIET on
SET SESSION AUTHORIZATION postgres;
SELECT CDB_DisableGhostTablesTrigger();
2019-03-08 15:28:06 +08:00
SET SESSION AUTHORIZATION "fulano";
2019-03-07 01:19:38 +08:00
\set QUIET off
SELECT to_regclass('cartodb.cdb_ddl_execution'); -- not exists
DROP TABLE tmp; -- _CDB_LinkGhostTables not called
2019-03-07 01:19:38 +08:00
-- Cleanup
2019-03-07 01:19:38 +08:00
\set QUIET on
SET SESSION AUTHORIZATION postgres;
REVOKE EXECUTE ON FUNCTION CDB_LinkGhostTables(text) FROM "fulano";
2019-03-08 15:28:06 +08:00
REVOKE EXECUTE ON FUNCTION CDB_Username() FROM "fulano";
REVOKE ALL ON SCHEMA cartodb FROM "fulano";
DROP ROLE "fulano";
2019-03-08 19:03:55 +08:00
DELETE FROM cdb_conf WHERE key = 'api_keys_fulano' OR key = 'invalidation_service';
2019-03-07 01:19:38 +08:00
\set QUIET off