From 3cd5e45029d9a9bf8518e66b668289ffe9d25937 Mon Sep 17 00:00:00 2001 From: Laurence Isla Date: Thu, 17 Sep 2026 21:11:34 -0500 Subject: [PATCH] fix: pgrst_ddl_watch triggering PostgREST notifications unnecessarily - When a trigger is created on a temporary table - When objects are created inside Supabase schemas: auth, realtime, storage --- migrations/schema-15.sql | 14 +++++++++++--- migrations/schema-17.sql | 14 +++++++++++--- migrations/schema-orioledb-17.sql | 14 +++++++++++--- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/migrations/schema-15.sql b/migrations/schema-15.sql index 322f47404c..4766d32619 100644 --- a/migrations/schema-15.sql +++ b/migrations/schema-15.sql @@ -339,13 +339,22 @@ BEGIN , 'CREATE VIEW', 'ALTER VIEW' , 'CREATE MATERIALIZED VIEW', 'ALTER MATERIALIZED VIEW' , 'CREATE FUNCTION', 'ALTER FUNCTION' - , 'CREATE TRIGGER' , 'CREATE TYPE', 'ALTER TYPE' , 'CREATE RULE' , 'COMMENT' ) -- don't notify in case of CREATE TEMP table or other objects created on pg_temp - AND cmd.schema_name is distinct from 'pg_temp' + -- also exclude any objects inside Supabase schemas + AND COALESCE(cmd.schema_name, '') not in ('pg_temp', 'auth', 'realtime', 'storage') + OR ( + -- we validate if the trigger is created on a temporary table (relpersistence = 't') + cmd.command_tag = 'CREATE TRIGGER' + AND NOT EXISTS ( + SELECT 1 + FROM pg_class c JOIN pg_trigger t ON c.oid = t.tgrelid + WHERE t.oid = cmd.objid AND c.relpersistence = 't' + ) + ) THEN NOTIFY pgrst, 'reload schema'; END IF; @@ -819,4 +828,3 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop -- \unrestrict SupabaseTestDumpKey123 - diff --git a/migrations/schema-17.sql b/migrations/schema-17.sql index 2cbfa1b146..aa43623791 100644 --- a/migrations/schema-17.sql +++ b/migrations/schema-17.sql @@ -340,13 +340,22 @@ BEGIN , 'CREATE VIEW', 'ALTER VIEW' , 'CREATE MATERIALIZED VIEW', 'ALTER MATERIALIZED VIEW' , 'CREATE FUNCTION', 'ALTER FUNCTION' - , 'CREATE TRIGGER' , 'CREATE TYPE', 'ALTER TYPE' , 'CREATE RULE' , 'COMMENT' ) -- don't notify in case of CREATE TEMP table or other objects created on pg_temp - AND cmd.schema_name is distinct from 'pg_temp' + -- also exclude any objects inside Supabase schemas + AND COALESCE(cmd.schema_name, '') not in ('pg_temp', 'auth', 'realtime', 'storage') + OR ( + -- we validate if the trigger is created on a temporary table (relpersistence = 't') + cmd.command_tag = 'CREATE TRIGGER' + AND NOT EXISTS ( + SELECT 1 + FROM pg_class c JOIN pg_trigger t ON c.oid = t.tgrelid + WHERE t.oid = cmd.objid AND c.relpersistence = 't' + ) + ) THEN NOTIFY pgrst, 'reload schema'; END IF; @@ -820,4 +829,3 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop -- \unrestrict SupabaseTestDumpKey123 - diff --git a/migrations/schema-orioledb-17.sql b/migrations/schema-orioledb-17.sql index c1617fdc60..e8d3a7d4b7 100644 --- a/migrations/schema-orioledb-17.sql +++ b/migrations/schema-orioledb-17.sql @@ -354,13 +354,22 @@ BEGIN , 'CREATE VIEW', 'ALTER VIEW' , 'CREATE MATERIALIZED VIEW', 'ALTER MATERIALIZED VIEW' , 'CREATE FUNCTION', 'ALTER FUNCTION' - , 'CREATE TRIGGER' , 'CREATE TYPE', 'ALTER TYPE' , 'CREATE RULE' , 'COMMENT' ) -- don't notify in case of CREATE TEMP table or other objects created on pg_temp - AND cmd.schema_name is distinct from 'pg_temp' + -- also exclude any objects inside Supabase schemas + AND COALESCE(cmd.schema_name, '') not in ('pg_temp', 'auth', 'realtime', 'storage') + OR ( + -- we validate if the trigger is created on a temporary table (relpersistence = 't') + cmd.command_tag = 'CREATE TRIGGER' + AND NOT EXISTS ( + SELECT 1 + FROM pg_class c JOIN pg_trigger t ON c.oid = t.tgrelid + WHERE t.oid = cmd.objid AND c.relpersistence = 't' + ) + ) THEN NOTIFY pgrst, 'reload schema'; END IF; @@ -834,4 +843,3 @@ CREATE EVENT TRIGGER pgrst_drop_watch ON sql_drop -- \unrestrict SupabaseTestDumpKey123 -