2019-03-07 01:19:38 +08:00
|
|
|
-- Create user and enable Ghost tables trigger
|
|
|
|
\set QUIET on
|
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":[]}');
|
|
|
|
SET SESSION AUTHORIZATION "fulano";
|
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-07 01:19:38 +08:00
|
|
|
\set QUIET off
|