-
Notifications
You must be signed in to change notification settings - Fork 3
feat(migrations): create apify_scraper_runs digest-batch table (supersedes #41) #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
supabase/migrations/20260709180000_create_apify_scraper_runs.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| -- Create apify_scraper_runs: digest-batch bookkeeping for scrape runs | ||
| -- (recoupable/chat#1855, PR #2 of 6). | ||
| -- | ||
| -- One artist-socials scrape starts one Apify run per platform; each completes | ||
| -- independently via its own webhook invocation, sharing no memory with its | ||
| -- siblings. To send ONE consolidated "new posts" digest per scrape instead of | ||
| -- one email per platform, a completing webhook must answer three questions its | ||
| -- own request can't: | ||
| -- which runs are my batch siblings? -> batch_id (Apify can't group runs | ||
| -- by our scrape call, and siblings | ||
| -- don't exist yet when the first | ||
| -- run's webhook is registered) | ||
| -- am I the last one to finish? -> completed_at on every sibling | ||
| -- (Apify run status is NOT a | ||
| -- substitute: SUCCEEDED means the | ||
| -- scrape finished, not that our | ||
| -- webhook processed it and wrote | ||
| -- new_post_urls) | ||
| -- what did the earlier runs find? -> new_post_urls (the pre-upsert | ||
| -- diff against posts; the upsert | ||
| -- destroys it moments later, so it | ||
| -- cannot be re-derived at digest | ||
| -- time) | ||
| -- | ||
| -- Supersedes database#41, which ALTERed this table without creating it: | ||
| -- database#39 (the chat#1840 ownership map) was closed unmerged when run | ||
| -- polling moved to the capability model, so the table never existed (42P01 on | ||
| -- prod). This table is scoped to digest bookkeeping only — it is NOT an | ||
| -- ownership/authorization map; the chat#1840 decision stands and polling auth | ||
| -- stays capability-based. | ||
| -- | ||
| -- Loose ids, no FKs (like email_send_log — bookkeeping shouldn't | ||
| -- cascade-delete with accounts/socials). Written by api insertApifyScraperRuns | ||
| -- (upsert on run_id at scrape start) + completeApifyScraperRun (webhook); read | ||
| -- by selectApifyScraperRunsByBatch (recoupable/api#760). | ||
|
|
||
| CREATE TABLE IF NOT EXISTS public.apify_scraper_runs ( | ||
| run_id TEXT PRIMARY KEY, -- Apify run id (natural key; one row per started run) | ||
| created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), | ||
| account_id UUID NOT NULL, -- account whose scrape started the run (denormalized audit) | ||
| social_id UUID, -- scraped social profile | ||
| platform TEXT, -- 'instagram' | 'tiktok' | 'x' | ... (digest section label) | ||
| batch_id UUID, -- minted per POST /api/artist/socials/scrape call; siblings share it | ||
| completed_at TIMESTAMP WITH TIME ZONE, -- set when OUR webhook finished processing this run's results | ||
| new_post_urls JSONB -- post URLs genuinely new to the platform (diffed against posts BEFORE upsert) | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS apify_scraper_runs_batch_id_idx | ||
| ON public.apify_scraper_runs (batch_id) | ||
| WHERE batch_id IS NOT NULL; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Enable RLS on the table to match the service-wide convention for internal tables containing account-scoped data (error_logs has it; email_send_log added it in the very next migration). Service-role writes bypass RLS, so net behavior is unchanged, but it closes the gap if anon/authenticated roles ever gain INSERT/UPDATE on this table.
Prompt for AI agents