diff --git a/supabase/migrations/20260903101000_notification_dispatch_cron.sql b/supabase/migrations/20260903101000_notification_dispatch_cron.sql new file mode 100644 index 0000000..82d80cb --- /dev/null +++ b/supabase/migrations/20260903101000_notification_dispatch_cron.sql @@ -0,0 +1,22 @@ +-- 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. +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), '') <> '' + $$ +);