From b09499a63a8ff854691151ec816137d085d898de Mon Sep 17 00:00:00 2001 From: Sweets Sweetman Date: Mon, 6 Jul 2026 16:53:13 -0500 Subject: [PATCH] feat(migrations): digest-batch columns on apify_scraper_runs batch_id + completed_at + new_post_urls so per-platform scrape webhook completions can find their siblings and assemble one consolidated new-posts digest per scrape (recoupable/chat#1855, PR #2 of 6). Co-Authored-By: Claude Fable 5 --- ...090000_apify_runs_digest_batch_columns.sql | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 supabase/migrations/20260707090000_apify_runs_digest_batch_columns.sql diff --git a/supabase/migrations/20260707090000_apify_runs_digest_batch_columns.sql b/supabase/migrations/20260707090000_apify_runs_digest_batch_columns.sql new file mode 100644 index 0000000..20aa99e --- /dev/null +++ b/supabase/migrations/20260707090000_apify_runs_digest_batch_columns.sql @@ -0,0 +1,23 @@ +-- Digest-batch columns for apify_scraper_runs (recoupable/chat#1855, PR #2 of 6). +-- +-- One artist-socials scrape (POST /api/artist/socials/scrape) starts one Apify +-- run per platform; each completes independently via webhook. To send ONE +-- consolidated "new posts" digest per scrape instead of one email per platform, +-- completions must find their sibling runs and know what each found: +-- batch_id — shared id minted per scrape call; siblings share it. +-- completed_at — set by the webhook when the run's results are processed; +-- the batch's last writer assembles and sends the digest. +-- new_post_urls — post URLs genuinely new to the platform found by this run +-- (diffed against posts before insert); the digest's content. +-- +-- Nullable, no FKs, no backfill: rows predating this migration simply never +-- digest (same loose-ids stance as the table's creation in chat#1840). + +ALTER TABLE public.apify_scraper_runs + ADD COLUMN IF NOT EXISTS batch_id UUID, + ADD COLUMN IF NOT EXISTS completed_at TIMESTAMP WITH TIME ZONE, + ADD COLUMN IF NOT EXISTS new_post_urls JSONB; + +CREATE INDEX IF NOT EXISTS apify_scraper_runs_batch_id_idx + ON public.apify_scraper_runs (batch_id) + WHERE batch_id IS NOT NULL;