Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
0039f70975 | ||
|
690edd27b7 | ||
|
e315ac09de | ||
|
e061b1e8e6 | ||
|
01528ef475 | ||
|
e49e91fa0d |
8
NEWS
8
NEWS
@ -1,3 +1,11 @@
|
||||
0.x.0
|
||||
-----
|
||||
|
||||
New features:
|
||||
|
||||
- Added CDB_UserDomain
|
||||
- Adds table_sync trigger on CDB_TableMetadata to call cdb_table_sync_* functions
|
||||
|
||||
0.2.0dev - 2014-MM-DD
|
||||
------------------
|
||||
|
||||
|
@ -118,3 +118,66 @@ CREATE TRIGGER table_modified AFTER INSERT OR UPDATE
|
||||
ON CDB_TableMetadata FOR EACH ROW EXECUTE PROCEDURE
|
||||
_CDB_TableMetadata_Updated();
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Trigger invalidating varnish whenever CDB_TableMetadata
|
||||
-- record change.
|
||||
--
|
||||
CREATE OR REPLACE FUNCTION _CDB_TableMetadata_Table_Sync()
|
||||
RETURNS trigger AS
|
||||
$$
|
||||
DECLARE
|
||||
tabid INTEGER;
|
||||
tabname TEXT;
|
||||
func TEXT;
|
||||
rec RECORD;
|
||||
found BOOL;
|
||||
BEGIN
|
||||
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
tabid = NEW.tabname::OID;
|
||||
tabname = NEW.tabname;
|
||||
func = 'cdb_table_sync_created';
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
RETURN NULL;
|
||||
-- SEE CDB-3148
|
||||
-- tabid = NEW.tabname::OID;
|
||||
-- tabname = NEW.tabname;
|
||||
-- func = 'cdb_table_sync_updated';
|
||||
ELSE
|
||||
tabid = OLD.tabname::OID;
|
||||
tabname = OLD.tabname;
|
||||
func = 'cdb_table_sync_deleted';
|
||||
END IF;
|
||||
|
||||
found := false;
|
||||
FOR rec IN SELECT u.usesuper, u.usename, n.nspname, p.proname
|
||||
FROM pg_proc p, pg_namespace n, pg_user u
|
||||
WHERE p.proname = func
|
||||
AND p.pronamespace = n.oid
|
||||
AND n.nspname IN ('public', 'cartodb')
|
||||
AND u.usesysid = p.proowner
|
||||
AND u.usesuper
|
||||
ORDER BY n.nspname
|
||||
LOOP
|
||||
EXECUTE 'SELECT ' || quote_ident(rec.nspname) || '.'
|
||||
|| quote_ident(rec.proname)
|
||||
|| '(' || quote_literal(tabid) || ',' || quote_literal(tabname) || ')';
|
||||
found := true;
|
||||
EXIT;
|
||||
END LOOP;
|
||||
IF NOT found THEN RAISE WARNING 'Missing Table Sync function()'; END IF;
|
||||
|
||||
RETURN NULL;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE plpgsql VOLATILE SECURITY DEFINER;
|
||||
|
||||
DROP TRIGGER IF EXISTS table_sync ON CDB_TableMetadata;
|
||||
-- NOTE: on DELETE we would be unable to convert the table
|
||||
-- oid (regclass) to its name
|
||||
CREATE TRIGGER table_sync AFTER INSERT OR UPDATE OR DELETE
|
||||
ON CDB_TableMetadata FOR EACH ROW EXECUTE PROCEDURE
|
||||
_CDB_TableMetadata_Table_Sync();
|
||||
|
||||
|
18
scripts-available/CDB_UserDomain.sql
Normal file
18
scripts-available/CDB_UserDomain.sql
Normal file
@ -0,0 +1,18 @@
|
||||
-- Function that setups user's host, port and http/https inside his own DB.
|
||||
-- Used for HTTP table sync functions.
|
||||
CREATE OR REPLACE FUNCTION CDB_SetUserDomain(host text, port int8, secure boolean)
|
||||
RETURNS VOID AS
|
||||
$$
|
||||
DECLARE
|
||||
sql TEXT;
|
||||
BEGIN
|
||||
sql := 'CREATE OR REPLACE FUNCTION public._CDB_UserDomain() '
|
||||
|| ' RETURNS TABLE (host text, port int8, secure boolean) '
|
||||
|| ' AS $X$ '
|
||||
|| ' SELECT ''' || host || '''::text, ' || port || '::int8, ' || secure || '::boolean '
|
||||
|| ' $X$ LANGUAGE sql IMMUTABLE';
|
||||
EXECUTE sql;
|
||||
RETURN;
|
||||
END
|
||||
$$
|
||||
LANGUAGE 'plpgsql' VOLATILE STRICT;
|
1
scripts-enabled/210-CDB_UserDomain.sql
Symbolic link
1
scripts-enabled/210-CDB_UserDomain.sql
Symbolic link
@ -0,0 +1 @@
|
||||
../scripts-available/CDB_UserDomain.sql
|
Loading…
Reference in New Issue
Block a user