move cdb_ddl_execution table creation/drop to functions

This commit is contained in:
Gonzalo Riestra
2019-03-11 14:02:45 +01:00
parent 1a271d977b
commit 65d51fd8bd
3 changed files with 27 additions and 29 deletions

View File

@@ -1,12 +1,12 @@
-- Create user and enable Ghost tables trigger
\set QUIET on
SET client_min_messages TO error;
SELECT CDB_EnableGhostTablesTrigger();
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";
SELECT CDB_EnableGhostTablesTrigger();
GRANT EXECUTE ON FUNCTION CDB_LinkGhostTables(text) TO "fulano";
INSERT INTO cdb_conf (key, value) VALUES ('api_keys_fulano', '{"username": "fulanito", "permissions":[]}');
INSERT INTO cdb_conf (key, value) VALUES ('invalidation_service', '{"host": "fake-tis-host"}');
SET SESSION AUTHORIZATION "fulano";
@@ -16,6 +16,7 @@ SET client_min_messages TO notice;
SELECT CDB_LinkGhostTables(); -- _CDB_LinkGhostTables called
BEGIN;
SELECT to_regclass('cartodb.cdb_ddl_execution'); -- exists
SELECT COUNT(*) FROM cartodb.cdb_ddl_execution; -- 0
CREATE TABLE tmp(id INT);
SELECT COUNT(*) FROM cartodb.cdb_ddl_execution; -- 1
@@ -28,18 +29,14 @@ SELECT CDB_DisableGhostTablesTrigger();
SET SESSION AUTHORIZATION "fulano";
\set QUIET off
BEGIN;
SELECT COUNT(*) FROM cartodb.cdb_ddl_execution; -- 0
DROP TABLE tmp;
SELECT COUNT(*) FROM cartodb.cdb_ddl_execution; -- 0
END; -- _CDB_LinkGhostTables not called
SELECT to_regclass('cartodb.cdb_ddl_execution'); -- not exists
DROP TABLE tmp; -- _CDB_LinkGhostTables not called
-- Clean up
-- Cleanup
\set QUIET on
SET SESSION AUTHORIZATION postgres;
REVOKE EXECUTE ON FUNCTION CDB_LinkGhostTables() FROM "fulano";
REVOKE EXECUTE ON FUNCTION CDB_LinkGhostTables(text) 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";
DELETE FROM cdb_conf WHERE key = 'api_keys_fulano' OR key = 'invalidation_service';