Add hook and test for add column, add wiki reference in README
This commit is contained in:
@@ -3,6 +3,8 @@ cartodb-postgresql
|
|||||||
|
|
||||||
PostgreSQL extension for CartoDB
|
PostgreSQL extension for CartoDB
|
||||||
|
|
||||||
|
See https://github.com/CartoDB/cartodb/wiki/CartoDB-PostgreSQL-extension
|
||||||
|
|
||||||
Depdenencies
|
Depdenencies
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
|||||||
+9
-17
@@ -17,11 +17,10 @@ BEGIN
|
|||||||
-- We're only interested in real relations
|
-- We're only interested in real relations
|
||||||
IF (event_info.new).relkind != 'r' THEN RETURN; END IF;
|
IF (event_info.new).relkind != 'r' THEN RETURN; END IF;
|
||||||
|
|
||||||
RAISE NOTICE 'Relation % of kind % created in namespace oid %',
|
RAISE DEBUG 'Relation % of kind % created in namespace oid %',
|
||||||
event_info.relation, (event_info.new).relkind, (event_info.new).relnamespace;
|
event_info.relation, (event_info.new).relkind, (event_info.new).relnamespace;
|
||||||
|
|
||||||
-- We don't want to react to alters triggered by superuser,
|
-- We don't want to react to alters triggered by superuser,
|
||||||
-- or we'd enter an infinite loop here
|
|
||||||
IF current_setting('is_superuser') = 'on' THEN
|
IF current_setting('is_superuser') = 'on' THEN
|
||||||
RAISE DEBUG 'no ddl trigger for superuser';
|
RAISE DEBUG 'no ddl trigger for superuser';
|
||||||
RETURN;
|
RETURN;
|
||||||
@@ -45,14 +44,13 @@ BEGIN
|
|||||||
|
|
||||||
SELECT oid,* FROM pg_class WHERE oid = event_info.relation INTO rel;
|
SELECT oid,* FROM pg_class WHERE oid = event_info.relation INTO rel;
|
||||||
|
|
||||||
RAISE NOTICE 'Column % altered by % (superuser? %) in relation % of kind %',
|
RAISE DEBUG 'Column % altered by % (superuser? %) in relation % of kind %',
|
||||||
(event_info.old).attname, current_user, current_setting('is_superuser'), event_info.relation::regclass, rel.relkind;
|
(event_info.old).attname, current_user, current_setting('is_superuser'), event_info.relation::regclass, rel.relkind;
|
||||||
|
|
||||||
-- We're only interested in real relations
|
-- We're only interested in real relations
|
||||||
IF rel.relkind != 'r' THEN RETURN; END IF;
|
IF rel.relkind != 'r' THEN RETURN; END IF;
|
||||||
|
|
||||||
-- We don't want to react to alters triggered by superuser,
|
-- We don't want to react to alters triggered by superuser,
|
||||||
-- or we'd enter an infinite loop here
|
|
||||||
IF current_setting('is_superuser') = 'on' THEN
|
IF current_setting('is_superuser') = 'on' THEN
|
||||||
RAISE DEBUG 'no ddl trigger for superuser';
|
RAISE DEBUG 'no ddl trigger for superuser';
|
||||||
RETURN;
|
RETURN;
|
||||||
@@ -64,7 +62,7 @@ BEGIN
|
|||||||
|
|
||||||
PERFORM cdb_enable_ddl_hooks();
|
PERFORM cdb_enable_ddl_hooks();
|
||||||
|
|
||||||
-- TODO: invalidate varnish ?
|
-- TODO: invalidate varnish
|
||||||
|
|
||||||
END; $$;
|
END; $$;
|
||||||
-- }
|
-- }
|
||||||
@@ -81,14 +79,13 @@ BEGIN
|
|||||||
|
|
||||||
SELECT oid,* FROM pg_class WHERE oid = event_info.relation INTO rel;
|
SELECT oid,* FROM pg_class WHERE oid = event_info.relation INTO rel;
|
||||||
|
|
||||||
RAISE NOTICE 'Column % drop by % (superuser? %) in relation % of kind %',
|
RAISE DEBUG 'Column % drop by % (superuser? %) in relation % of kind %',
|
||||||
(event_info.old).attname, current_user, current_setting('is_superuser'), event_info.relation::regclass, rel.relkind;
|
(event_info.old).attname, current_user, current_setting('is_superuser'), event_info.relation::regclass, rel.relkind;
|
||||||
|
|
||||||
-- We're only interested in real relations
|
-- We're only interested in real relations
|
||||||
IF rel.relkind != 'r' THEN RETURN; END IF;
|
IF rel.relkind != 'r' THEN RETURN; END IF;
|
||||||
|
|
||||||
-- We don't want to react to drops triggered by superuser,
|
-- We don't want to react to drops triggered by superuser,
|
||||||
-- or we'd enter an infinite loop here
|
|
||||||
IF current_setting('is_superuser') = 'on' THEN
|
IF current_setting('is_superuser') = 'on' THEN
|
||||||
RAISE DEBUG 'no ddl trigger for superuser';
|
RAISE DEBUG 'no ddl trigger for superuser';
|
||||||
RETURN;
|
RETURN;
|
||||||
@@ -100,7 +97,7 @@ BEGIN
|
|||||||
|
|
||||||
PERFORM cdb_enable_ddl_hooks();
|
PERFORM cdb_enable_ddl_hooks();
|
||||||
|
|
||||||
-- TODO: invalidate varnish ?
|
-- TODO: invalidate varnish
|
||||||
|
|
||||||
END; $$;
|
END; $$;
|
||||||
-- }
|
-- }
|
||||||
@@ -117,24 +114,19 @@ BEGIN
|
|||||||
|
|
||||||
SELECT oid,* FROM pg_class WHERE oid = event_info.relation INTO rel;
|
SELECT oid,* FROM pg_class WHERE oid = event_info.relation INTO rel;
|
||||||
|
|
||||||
RAISE NOTICE 'Column % add by % (superuser? %) in relation % of kind %',
|
RAISE DEBUG 'Column % added by % (superuser? %) in relation % of kind %',
|
||||||
(event_info.old).attname, current_user, current_setting('is_superuser'), event_info.relation::regclass, rel.relkind;
|
(event_info.new).attname, current_user, current_setting('is_superuser'), event_info.relation::regclass, rel.relkind;
|
||||||
|
|
||||||
-- We're only interested in real relations
|
-- We're only interested in real relations
|
||||||
IF rel.relkind != 'r' THEN RETURN; END IF;
|
IF rel.relkind != 'r' THEN RETURN; END IF;
|
||||||
|
|
||||||
-- We don't want to react to drops triggered by superuser,
|
-- We don't want to react to drops triggered by superuser,
|
||||||
-- or we'd enter an infinite loop here
|
|
||||||
IF current_setting('is_superuser') = 'on' THEN
|
IF current_setting('is_superuser') = 'on' THEN
|
||||||
RAISE DEBUG 'no ddl trigger for superuser';
|
RAISE DEBUG 'no ddl trigger for superuser';
|
||||||
RETURN;
|
RETURN;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
--PERFORM cdb_disable_ddl_hooks();
|
-- TODO: invalidate varnish
|
||||||
--PERFORM public.CDB_CartodbfyTable(event_info.relation);
|
|
||||||
--PERFORM cdb_enable_ddl_hooks();
|
|
||||||
|
|
||||||
-- TODO: invalidate varnish ?
|
|
||||||
|
|
||||||
END; $$;
|
END; $$;
|
||||||
-- }
|
-- }
|
||||||
@@ -151,7 +143,7 @@ CREATE OR REPLACE FUNCTION cdb_enable_ddl_hooks() returns void AS $$
|
|||||||
CREATE EVENT TRIGGER cdb_on_relation_create ON "relation_create" EXECUTE PROCEDURE cdb_handle_create_table();
|
CREATE EVENT TRIGGER cdb_on_relation_create ON "relation_create" EXECUTE PROCEDURE cdb_handle_create_table();
|
||||||
CREATE EVENT TRIGGER cdb_on_alter_column ON "column_alter" EXECUTE PROCEDURE cdb_handle_alter_column();
|
CREATE EVENT TRIGGER cdb_on_alter_column ON "column_alter" EXECUTE PROCEDURE cdb_handle_alter_column();
|
||||||
CREATE EVENT TRIGGER cdb_on_drop_column ON "column_drop" EXECUTE PROCEDURE cdb_handle_drop_column();
|
CREATE EVENT TRIGGER cdb_on_drop_column ON "column_drop" EXECUTE PROCEDURE cdb_handle_drop_column();
|
||||||
CREATE EVENT TRIGGER cdb_on_add_column ON "column_drop" EXECUTE PROCEDURE cdb_handle_add_column();
|
CREATE EVENT TRIGGER cdb_on_add_column ON "column_add" EXECUTE PROCEDURE cdb_handle_add_column();
|
||||||
$$ LANGUAGE sql;
|
$$ LANGUAGE sql;
|
||||||
|
|
||||||
SELECT cdb_enable_ddl_hooks();
|
SELECT cdb_enable_ddl_hooks();
|
||||||
|
|||||||
@@ -16,4 +16,6 @@ alter table c.t3 rename column the_geom_webmercator to webmerc2;
|
|||||||
select * from c.t3;
|
select * from c.t3;
|
||||||
alter table c.t3 drop column the_geom_webmercator;
|
alter table c.t3 drop column the_geom_webmercator;
|
||||||
select * from c.t3;
|
select * from c.t3;
|
||||||
|
alter table c.t3 add column id2 int;
|
||||||
|
select * from c.t3;
|
||||||
drop schema c cascade;
|
drop schema c cascade;
|
||||||
|
|||||||
Reference in New Issue
Block a user