1
0
Fork 0
fahrPool/supabase/migrations/20260903101000_notification...

25 lines
1.2 KiB
SQL

-- Minuetlicher Anstoss der Dispatch-Route. URL und Secret stehen bewusst
-- NICHT hier (umgebungsabhaengig, kein Secret in Git), sondern in den
-- DB-Settings app.notification_dispatch_url / app.notification_dispatch_secret,
-- die pro Stack out-of-band gesetzt werden. Ist die URL leer/ungesetzt (z.B.
-- lokaler CLI-Dev-Stack), verhindert die where-Bedingung jeden http_post --
-- der Job existiert dann, tut aber nichts. Gleiches gilt, solange
-- app.notification_dispatch_url ODER app.notification_dispatch_secret leer ist.
create extension if not exists pg_cron;
create extension if not exists pg_net;
select cron.schedule(
'notification-dispatch',
'* * * * *',
$$
select net.http_post(
url := current_setting('app.notification_dispatch_url', true),
headers := jsonb_build_object(
'Content-Type', 'application/json',
'Authorization', 'Bearer ' || current_setting('app.notification_dispatch_secret', true)),
body := '{}'::jsonb)
where coalesce(current_setting('app.notification_dispatch_url', true), '') <> ''
and coalesce(current_setting('app.notification_dispatch_secret', true), '') <> ''
$$
);