@@ -5,25 +5,33 @@ CREATE OR REPLACE FUNCTION extensions.pgrst_ddl_watch() RETURNS event_trigger
55 AS $$
66DECLARE
77 cmd record;
8+ obj_schema text ;
89BEGIN
910 FOR cmd IN SELECT * FROM pg_event_trigger_ddl_commands()
1011 LOOP
12+ -- triggers and rules have no schema of their own (schema_name is NULL),
13+ -- so use the schema of the table they belong to
14+ obj_schema := CASE
15+ WHEN cmd .object_type IN (' trigger' , ' rule' )
16+ THEN (pg_identify_object_as_address(cmd .classid , cmd .objid , cmd .objsubid )).object_names[1 ]
17+ ELSE cmd .schema_name
18+ END;
19+
1120 IF cmd .command_tag IN (
1221 ' CREATE SCHEMA' , ' ALTER SCHEMA'
1322 , ' CREATE TABLE' , ' CREATE TABLE AS' , ' SELECT INTO' , ' ALTER TABLE'
1423 , ' CREATE FOREIGN TABLE' , ' ALTER FOREIGN TABLE'
1524 , ' CREATE VIEW' , ' ALTER VIEW'
1625 , ' CREATE MATERIALIZED VIEW' , ' ALTER MATERIALIZED VIEW'
1726 , ' CREATE FUNCTION' , ' ALTER FUNCTION'
27+ , ' CREATE TRIGGER'
1828 , ' CREATE TYPE' , ' ALTER TYPE'
1929 , ' CREATE RULE'
2030 , ' COMMENT'
2131 )
2232 -- don't notify in case of CREATE TEMP table or other objects created on pg_temp
2333 -- also exclude any objects inside Supabase schemas
24- AND COALESCE(cmd .schema_name , ' ' ) NOT IN (' pg_temp' , ' auth' , ' realtime' , ' _realtime' , ' storage' )
25- -- Exclude any trigger created on temp tables (object_identity = 'trigger on pg_temp.table')
26- OR (cmd .command_tag = ' CREATE TRIGGER' AND cmd .object_identity NOT LIKE ' % pg\_ temp.%' )
34+ AND COALESCE(obj_schema, ' ' ) NOT IN (' pg_temp' , ' auth' , ' realtime' , ' _realtime' , ' storage' )
2735 THEN
2836 NOTIFY pgrst, ' reload schema' ;
2937 END IF;
@@ -36,24 +44,31 @@ CREATE OR REPLACE FUNCTION extensions.pgrst_drop_watch() RETURNS event_trigger
3644 AS $$
3745DECLARE
3846 obj record;
47+ obj_schema text ;
3948BEGIN
4049 FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects()
4150 LOOP
51+ -- triggers and rules have no schema of their own (schema_name is NULL),
52+ -- so use the schema of the table they belonged to
53+ obj_schema := CASE
54+ WHEN obj .object_type IN (' trigger' , ' rule' ) THEN obj .address_names [1 ]
55+ ELSE obj .schema_name
56+ END;
57+
4258 IF obj .object_type IN (
4359 ' schema'
4460 , ' table'
4561 , ' foreign table'
4662 , ' view'
4763 , ' materialized view'
4864 , ' function'
65+ , ' trigger'
4966 , ' type'
5067 , ' rule'
5168 )
5269 AND obj .is_temporary IS false -- no pg_temp objects
5370 -- also exclude any objects inside Supabase schemas
54- AND COALESCE(obj .schema_name , ' ' ) NOT IN (' auth' , ' realtime' , ' _realtime' , ' storage' )
55- -- Exclude any trigger created on temp tables (object_identity = 'trigger on pg_temp.table')
56- OR ( obj .object_type = ' trigger' AND obj .object_identity NOT LIKE ' % pg\_ temp.%' )
71+ AND COALESCE(obj_schema, ' ' ) NOT IN (' pg_temp' , ' auth' , ' realtime' , ' _realtime' , ' storage' )
5772 THEN
5873 NOTIFY pgrst, ' reload schema' ;
5974 END IF;
0 commit comments