|
4 | 4 | -- |
5 | 5 | -- Prerequisites: |
6 | 6 | -- These Supabase config vars must be set before running this migration: |
7 | | --- ALTER DATABASE postgres SET app.site_url = 'https://your-vercel-url.vercel.app'; |
| 7 | +-- ALTER DATABASE postgres SET app.site_url = 'https://codingcat.dev'; |
8 | 8 | -- ALTER DATABASE postgres SET app.cron_secret = 'your-cron-secret-here'; |
9 | 9 | -- |
10 | 10 | -- You can set them in the Supabase dashboard under Database → Extensions, |
11 | 11 | -- or via SQL in the SQL Editor. |
12 | 12 | -- |
13 | 13 | -- Pipeline flow: |
14 | | --- 1. ingest-daily → discovers trends, creates Sanity doc (status: "researching" or "script_ready") |
15 | | --- 2. check-research → polls NotebookLM, enriches script, transitions to "script_ready" |
16 | | --- 3. check-renders → audio gen → Remotion render → upload → publish |
17 | | --- 4. sponsor-outreach → automated sponsor discovery + outreach emails |
| 14 | +-- 1. youtube-stats → daily YouTube analytics sync (renamed from daily-cron) |
| 15 | +-- 2. ingest-daily → discovers trends, creates Sanity doc (status: "researching" or "script_ready") |
| 16 | +-- 3. check-research → polls NotebookLM, enriches script, transitions to "script_ready" |
| 17 | +-- 4. check-renders → audio gen → Remotion render → upload → publish |
| 18 | +-- 5. sponsor-outreach → automated sponsor discovery + outreach emails |
18 | 19 | -- ========================================================================== |
19 | 20 |
|
20 | 21 | -- Enable required extensions |
21 | 22 | CREATE EXTENSION IF NOT EXISTS pg_cron; |
22 | 23 | CREATE EXTENSION IF NOT EXISTS pg_net; |
23 | 24 |
|
24 | 25 | -- --------------------------------------------------------------------------- |
25 | | --- Remove any existing schedules (idempotent re-runs) |
| 26 | +-- Remove old/renamed schedules (idempotent re-runs) |
26 | 27 | -- --------------------------------------------------------------------------- |
27 | 28 | -- pg_cron's unschedule() throws if the job doesn't exist, so we use DO blocks |
| 29 | + |
| 30 | +-- Old name → renamed to youtube-stats |
| 31 | +DO $$ |
| 32 | +BEGIN |
| 33 | + PERFORM cron.unschedule('daily-cron'); |
| 34 | +EXCEPTION WHEN OTHERS THEN |
| 35 | + NULL; |
| 36 | +END $$; |
| 37 | + |
| 38 | +-- Old name → replaced by ingest-daily |
| 39 | +DO $$ |
| 40 | +BEGIN |
| 41 | + PERFORM cron.unschedule('daily-content-ingest'); |
| 42 | +EXCEPTION WHEN OTHERS THEN |
| 43 | + NULL; |
| 44 | +END $$; |
| 45 | + |
| 46 | +-- Remove our own jobs too (for idempotent re-runs) |
| 47 | +DO $$ |
| 48 | +BEGIN |
| 49 | + PERFORM cron.unschedule('youtube-stats'); |
| 50 | +EXCEPTION WHEN OTHERS THEN |
| 51 | + NULL; |
| 52 | +END $$; |
| 53 | + |
28 | 54 | DO $$ |
29 | 55 | BEGIN |
30 | 56 | PERFORM cron.unschedule('ingest-daily'); |
@@ -53,8 +79,21 @@ EXCEPTION WHEN OTHERS THEN |
53 | 79 | NULL; |
54 | 80 | END $$; |
55 | 81 |
|
| 82 | +-- --------------------------------------------------------------------------- |
| 83 | +-- Schedule: YouTube Stats — daily at midnight UTC (renamed from daily-cron) |
| 84 | +-- --------------------------------------------------------------------------- |
| 85 | +SELECT cron.schedule( |
| 86 | + 'youtube-stats', |
| 87 | + '0 0 * * *', |
| 88 | + $$SELECT net.http_get( |
| 89 | + url := current_setting('app.site_url') || '/api/cron', |
| 90 | + headers := jsonb_build_object('Authorization', 'Bearer ' || current_setting('app.cron_secret')) |
| 91 | + )$$ |
| 92 | +); |
| 93 | + |
56 | 94 | -- --------------------------------------------------------------------------- |
57 | 95 | -- Schedule: Ingest — daily at 10:00 UTC |
| 96 | +-- Discovers trending topics, creates Sanity doc, starts NotebookLM research |
58 | 97 | -- --------------------------------------------------------------------------- |
59 | 98 | SELECT cron.schedule( |
60 | 99 | 'ingest-daily', |
|
0 commit comments