cartodb-postgresql/test/CDB_GhostTables.sql

47 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;
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() TO "fulano";
2019-03-07 01:19:38 +08:00
SELECT CDB_EnableGhostTablesTrigger();
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 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
BEGIN;
SELECT COUNT(*) FROM cartodb.cdb_ddl_execution; -- 0
2019-03-08 15:28:06 +08:00
DROP TABLE tmp;
2019-03-07 01:19:38 +08:00
SELECT COUNT(*) FROM cartodb.cdb_ddl_execution; -- 0
END; -- _CDB_LinkGhostTables not called
2019-03-08 15:28:06 +08:00
-- Clean up
2019-03-07 01:19:38 +08:00
\set QUIET on
SET SESSION AUTHORIZATION postgres;
2019-03-08 15:28:06 +08:00
REVOKE EXECUTE ON FUNCTION CDB_LinkGhostTables() FROM "fulano";
REVOKE EXECUTE ON FUNCTION CDB_Username() FROM "fulano";
REVOKE SELECT ON cartodb.cdb_ddl_execution 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