fix: extract Edge Functions base URL into a single shared SQL function
notify_booking_created() and notify_inquiry_created() each held their own literal copy of the local Edge Functions base URL. Introduce public.edge_functions_base_url() as the single source of truth so Task 9's production deploy only needs to update one function definition instead of two independent literals.
This commit is contained in:
@@ -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://<project-ref>.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))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user