mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 10:19:43 +00:00
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:
1 parent
04dee69888
commit
024dc4d288
1 file changed
+19
-49
@@ -15,15 +15,9 @@ AS $$
|
||||
|| function_name;
|
||||
$$;
|
||||
|
||||
-- For safety, abort if supabase_url is not set
|
||||
DO $$
|
||||
BEGIN
|
||||
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;
|
||||
$$;
|
||||
-- Resolve the URL when each job runs, rather than while migrations are applied.
|
||||
-- A fresh local database therefore remains reproducible and fails closed until
|
||||
-- its environment-specific URL is configured.
|
||||
|
||||
-- Safely unschedule all existing cron jobs (ignore if they don't exist)
|
||||
DO $$
|
||||
@@ -56,119 +50,95 @@ $$;
|
||||
SELECT cron.schedule(
|
||||
'send-pack-change-notifications',
|
||||
'*/5 * * * *',
|
||||
format(
|
||||
$cmd$
|
||||
SELECT net.http_post(
|
||||
url := %L,
|
||||
url := get_supabase_edge_function_url('send-pack-change-notification'),
|
||||
headers := jsonb_build_object('Content-Type', 'application/json'),
|
||||
body := '{}'::jsonb
|
||||
)
|
||||
$cmd$,
|
||||
get_supabase_edge_function_url('send-pack-change-notification')
|
||||
)
|
||||
$cmd$
|
||||
);
|
||||
|
||||
SELECT cron.schedule(
|
||||
'send-partner-activity-notifications',
|
||||
'*/5 * * * *',
|
||||
format(
|
||||
$cmd$
|
||||
SELECT net.http_post(
|
||||
url := %L,
|
||||
url := get_supabase_edge_function_url('send-partner-activity-notification'),
|
||||
headers := jsonb_build_object('Content-Type', 'application/json'),
|
||||
body := '{}'::jsonb
|
||||
)
|
||||
$cmd$,
|
||||
get_supabase_edge_function_url('send-partner-activity-notification')
|
||||
)
|
||||
$cmd$
|
||||
);
|
||||
|
||||
SELECT cron.schedule(
|
||||
'process-scheduled-releases',
|
||||
'*/5 * * * *',
|
||||
format(
|
||||
$cmd$
|
||||
SELECT net.http_post(
|
||||
url := %L,
|
||||
url := get_supabase_edge_function_url('process-scheduled-releases'),
|
||||
headers := jsonb_build_object('Content-Type', 'application/json'),
|
||||
body := '{}'::jsonb
|
||||
)
|
||||
$cmd$,
|
||||
get_supabase_edge_function_url('process-scheduled-releases')
|
||||
)
|
||||
$cmd$
|
||||
);
|
||||
|
||||
SELECT cron.schedule(
|
||||
'check-streak-milestones',
|
||||
'5 0 * * *',
|
||||
format(
|
||||
$cmd$
|
||||
SELECT net.http_post(
|
||||
url := %L,
|
||||
url := get_supabase_edge_function_url('check-streak-milestones'),
|
||||
headers := jsonb_build_object('Content-Type', 'application/json'),
|
||||
body := '{}'::jsonb
|
||||
)
|
||||
$cmd$,
|
||||
get_supabase_edge_function_url('check-streak-milestones')
|
||||
)
|
||||
$cmd$
|
||||
);
|
||||
|
||||
SELECT cron.schedule(
|
||||
'send-match-notification-digests',
|
||||
'* * * * *',
|
||||
format(
|
||||
$cmd$
|
||||
SELECT net.http_post(
|
||||
url := %L,
|
||||
url := get_supabase_edge_function_url('send-match-notification-digest'),
|
||||
headers := jsonb_build_object('Content-Type', 'application/json'),
|
||||
body := '{}'::jsonb
|
||||
)
|
||||
$cmd$,
|
||||
get_supabase_edge_function_url('send-match-notification-digest')
|
||||
)
|
||||
$cmd$
|
||||
);
|
||||
|
||||
SELECT cron.schedule(
|
||||
'send-weekly-summary',
|
||||
'0 10 * * 0',
|
||||
format(
|
||||
$cmd$
|
||||
SELECT net.http_post(
|
||||
url := %L,
|
||||
url := get_supabase_edge_function_url('send-weekly-summary'),
|
||||
headers := jsonb_build_object('Content-Type', 'application/json'),
|
||||
body := '{}'::jsonb
|
||||
)
|
||||
$cmd$,
|
||||
get_supabase_edge_function_url('send-weekly-summary')
|
||||
)
|
||||
$cmd$
|
||||
);
|
||||
|
||||
SELECT cron.schedule(
|
||||
'send-unpaired-reminders',
|
||||
'0 18 * * *',
|
||||
format(
|
||||
$cmd$
|
||||
SELECT net.http_post(
|
||||
url := %L,
|
||||
url := get_supabase_edge_function_url('send-unpaired-reminder'),
|
||||
headers := jsonb_build_object('Content-Type', 'application/json'),
|
||||
body := '{}'::jsonb
|
||||
)
|
||||
$cmd$,
|
||||
get_supabase_edge_function_url('send-unpaired-reminder')
|
||||
)
|
||||
$cmd$
|
||||
);
|
||||
|
||||
SELECT cron.schedule(
|
||||
'send-catchup-reminders',
|
||||
'0 17 * * *',
|
||||
format(
|
||||
$cmd$
|
||||
SELECT net.http_post(
|
||||
url := %L,
|
||||
url := get_supabase_edge_function_url('send-catchup-reminder'),
|
||||
headers := jsonb_build_object('Content-Type', 'application/json'),
|
||||
body := '{}'::jsonb
|
||||
)
|
||||
$cmd$,
|
||||
get_supabase_edge_function_url('send-catchup-reminder')
|
||||
)
|
||||
$cmd$
|
||||
);
|
||||
Reference in new issue
Block a user