diff --git a/supabase/migrations/20260808000003_notify_triggers.sql b/supabase/migrations/20260808000003_notify_triggers.sql index 5d9de66..3dcfd09 100644 --- a/supabase/migrations/20260808000003_notify_triggers.sql +++ b/supabase/migrations/20260808000003_notify_triggers.sql @@ -44,17 +44,33 @@ create extension if not exists pg_net with schema extensions; -- `extensions.net` as database.schema). Fixed to call `net.http_post` -- directly below. +-- Single source of truth for the Edge Functions base URL, used by both +-- notify_booking_created() and notify_inquiry_created() below. Task 9 +-- (production deploy) MUST update this function's return value to the real +-- deployed Edge Functions URL (e.g. https://.supabase.co/functions/v1) +-- when promoting to production. Because both trigger functions call through +-- this single function rather than each holding their own copy of the +-- literal, updating this one definition (and re-running the migration or an +-- equivalent `create or replace function` in production) is sufficient to +-- repoint both notification paths — there is no second copy to remember to +-- edit. +create or replace function public.edge_functions_base_url() +returns text +language sql +immutable +as $$ + select 'http://host.docker.internal:54321/functions/v1' +$$; + create or replace function public.notify_booking_created() returns trigger language plpgsql security definer set search_path = '' as $$ -declare - base_url text := 'http://host.docker.internal:54321/functions/v1'; begin perform net.http_post( - url := base_url || '/on-booking-created', + url := public.edge_functions_base_url() || '/on-booking-created', headers := jsonb_build_object('Content-Type', 'application/json'), body := jsonb_build_object('record', to_jsonb(new)) ); @@ -73,11 +89,9 @@ language plpgsql security definer set search_path = '' as $$ -declare - base_url text := 'http://host.docker.internal:54321/functions/v1'; begin perform net.http_post( - url := base_url || '/on-inquiry-created', + url := public.edge_functions_base_url() || '/on-inquiry-created', headers := jsonb_build_object('Content-Type', 'application/json'), body := jsonb_build_object('record', to_jsonb(new)) );