fix(database): defer cron URL resolution

Resolve each Edge Function URL when its cron job executes so fresh local databases can replay migrations before environment data is seeded. Missing configuration remains fail-closed instead of aborting database bootstrap.
This commit is contained in:
jjbrunton committed 2026-08-27 22:21:28 +01:00
1 parent 04dee69888
commit 024dc4d288
1 file changed
+27 -57
@@ -15,15 +15,9 @@ AS $$
|| function_name; || function_name;
$$; $$;
-- For safety, abort if supabase_url is not set -- Resolve the URL when each job runs, rather than while migrations are applied.
DO $$ -- A fresh local database therefore remains reproducible and fails closed until
BEGIN -- its environment-specific URL is configured.
IF (SELECT supabase_url FROM app_config LIMIT 1) IS NULL THEN
RAISE EXCEPTION 'app_config.supabase_url must be set before running this migration. '
'Run: UPDATE app_config SET supabase_url = ''https://<project-ref>.supabase.co'';';
END IF;
END;
$$;
-- Safely unschedule all existing cron jobs (ignore if they don't exist) -- Safely unschedule all existing cron jobs (ignore if they don't exist)
DO $$ DO $$
@@ -56,119 +50,95 @@ $$;
SELECT cron.schedule( SELECT cron.schedule(
'send-pack-change-notifications', 'send-pack-change-notifications',
'*/5 * * * *', '*/5 * * * *',
format( $cmd$
$cmd$
SELECT net.http_post( SELECT net.http_post(
url := %L, url := get_supabase_edge_function_url('send-pack-change-notification'),
headers := jsonb_build_object('Content-Type', 'application/json'), headers := jsonb_build_object('Content-Type', 'application/json'),
body := '{}'::jsonb body := '{}'::jsonb
) )
$cmd$, $cmd$
get_supabase_edge_function_url('send-pack-change-notification')
)
); );
SELECT cron.schedule( SELECT cron.schedule(
'send-partner-activity-notifications', 'send-partner-activity-notifications',
'*/5 * * * *', '*/5 * * * *',
format( $cmd$
$cmd$
SELECT net.http_post( SELECT net.http_post(
url := %L, url := get_supabase_edge_function_url('send-partner-activity-notification'),
headers := jsonb_build_object('Content-Type', 'application/json'), headers := jsonb_build_object('Content-Type', 'application/json'),
body := '{}'::jsonb body := '{}'::jsonb
) )
$cmd$, $cmd$
get_supabase_edge_function_url('send-partner-activity-notification')
)
); );
SELECT cron.schedule( SELECT cron.schedule(
'process-scheduled-releases', 'process-scheduled-releases',
'*/5 * * * *', '*/5 * * * *',
format( $cmd$
$cmd$
SELECT net.http_post( SELECT net.http_post(
url := %L, url := get_supabase_edge_function_url('process-scheduled-releases'),
headers := jsonb_build_object('Content-Type', 'application/json'), headers := jsonb_build_object('Content-Type', 'application/json'),
body := '{}'::jsonb body := '{}'::jsonb
) )
$cmd$, $cmd$
get_supabase_edge_function_url('process-scheduled-releases')
)
); );
SELECT cron.schedule( SELECT cron.schedule(
'check-streak-milestones', 'check-streak-milestones',
'5 0 * * *', '5 0 * * *',
format( $cmd$
$cmd$
SELECT net.http_post( SELECT net.http_post(
url := %L, url := get_supabase_edge_function_url('check-streak-milestones'),
headers := jsonb_build_object('Content-Type', 'application/json'), headers := jsonb_build_object('Content-Type', 'application/json'),
body := '{}'::jsonb body := '{}'::jsonb
) )
$cmd$, $cmd$
get_supabase_edge_function_url('check-streak-milestones')
)
); );
SELECT cron.schedule( SELECT cron.schedule(
'send-match-notification-digests', 'send-match-notification-digests',
'* * * * *', '* * * * *',
format( $cmd$
$cmd$
SELECT net.http_post( SELECT net.http_post(
url := %L, url := get_supabase_edge_function_url('send-match-notification-digest'),
headers := jsonb_build_object('Content-Type', 'application/json'), headers := jsonb_build_object('Content-Type', 'application/json'),
body := '{}'::jsonb body := '{}'::jsonb
) )
$cmd$, $cmd$
get_supabase_edge_function_url('send-match-notification-digest')
)
); );
SELECT cron.schedule( SELECT cron.schedule(
'send-weekly-summary', 'send-weekly-summary',
'0 10 * * 0', '0 10 * * 0',
format( $cmd$
$cmd$
SELECT net.http_post( SELECT net.http_post(
url := %L, url := get_supabase_edge_function_url('send-weekly-summary'),
headers := jsonb_build_object('Content-Type', 'application/json'), headers := jsonb_build_object('Content-Type', 'application/json'),
body := '{}'::jsonb body := '{}'::jsonb
) )
$cmd$, $cmd$
get_supabase_edge_function_url('send-weekly-summary')
)
); );
SELECT cron.schedule( SELECT cron.schedule(
'send-unpaired-reminders', 'send-unpaired-reminders',
'0 18 * * *', '0 18 * * *',
format( $cmd$
$cmd$
SELECT net.http_post( SELECT net.http_post(
url := %L, url := get_supabase_edge_function_url('send-unpaired-reminder'),
headers := jsonb_build_object('Content-Type', 'application/json'), headers := jsonb_build_object('Content-Type', 'application/json'),
body := '{}'::jsonb body := '{}'::jsonb
) )
$cmd$, $cmd$
get_supabase_edge_function_url('send-unpaired-reminder')
)
); );
SELECT cron.schedule( SELECT cron.schedule(
'send-catchup-reminders', 'send-catchup-reminders',
'0 17 * * *', '0 17 * * *',
format( $cmd$
$cmd$
SELECT net.http_post( SELECT net.http_post(
url := %L, url := get_supabase_edge_function_url('send-catchup-reminder'),
headers := jsonb_build_object('Content-Type', 'application/json'), headers := jsonb_build_object('Content-Type', 'application/json'),
body := '{}'::jsonb body := '{}'::jsonb
) )
$cmd$, $cmd$
get_supabase_edge_function_url('send-catchup-reminder')
)
); );