Configures Postgres triggers and database webhooks for event-driven architectures in Supabase.
97
97%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Critical
Do not install without reviewing
execute_sql tool MUST be available and authenticated.pg_net extension MUST be enabled. If not, HALT and instruct the operator to run CREATE EXTENSION IF NOT EXISTS pg_net;.row_to_json(NEW) for INSERT/UPDATE or row_to_json(OLD) for DELETE.net.http_post() from pg_net with:
Content-Type: application/json header.NEW for INSERT/UPDATE, OLD for DELETE).CREATE OR REPLACE FUNCTION statement via MCP execute_sql.Example — trigger function (use NEW/RETURN NEW for INSERT/UPDATE; substitute OLD/RETURN OLD for DELETE):
CREATE OR REPLACE FUNCTION notify_webhook_on_change()
RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
PERFORM net.http_post(
url := 'https://your-project.supabase.co/functions/v1/your-handler',
headers := '{"Content-Type": "application/json"}'::jsonb,
body := row_to_json(NEW)::text -- replace NEW with OLD for DELETE triggers
);
RETURN NEW; -- replace with RETURN OLD for DELETE triggers
END;
$$;CREATE TRIGGER bound to the target table.AFTER INSERT, AFTER UPDATE, or AFTER DELETE.OF <column_list> to watch only relevant columns. NEVER use bare AFTER UPDATE without a column list.FOR EACH ROW.CREATE TRIGGER statement via MCP execute_sql.Example — AFTER UPDATE OF specific columns:
CREATE TRIGGER trg_orders_webhook
AFTER UPDATE OF status, amount
ON public.orders
FOR EACH ROW
EXECUTE FUNCTION notify_webhook_on_change();Example — AFTER INSERT:
CREATE TRIGGER trg_orders_insert_webhook
AFTER INSERT
ON public.orders
FOR EACH ROW
EXECUTE FUNCTION notify_webhook_on_change();Example — AFTER DELETE:
CREATE TRIGGER trg_orders_delete_webhook
AFTER DELETE
ON public.orders
FOR EACH ROW
EXECUTE FUNCTION notify_webhook_on_delete();information_schema.triggers to confirm the trigger exists on the target table.pg_proc to confirm the trigger function exists.The agent MUST produce a report containing:
| Field | Value |
|---|---|
| Trigger Name | The created trigger identifier |
| Target Table | Schema-qualified table name |
| Events | INSERT / UPDATE / DELETE events bound |
| Column Watch List | Columns in UPDATE OF clause, or N/A |
| Destination Endpoint | The webhook URL |
| Function Name | The trigger function identifier |
| Status | DEPLOYED or FAILED |