Context
PR #258 fixed the code path — plot_count and last_plot_time now reconcile on every plot index and backfill. But existing storylines still have stale data from before the fix (e.g., storylines showing plot_count=1 despite having 3+ plots chained).
Task
Add a Supabase migration that reconciles all existing storylines.plot_count and last_plot_time from the plots table.
Migration SQL
UPDATE storylines s
SET plot_count = sub.cnt,
last_plot_time = sub.latest
FROM (
SELECT storyline_id,
COUNT(*) AS cnt,
MAX(block_timestamp) AS latest
FROM plots
GROUP BY storyline_id
) sub
WHERE s.storyline_id = sub.storyline_id
AND (s.plot_count != sub.cnt OR s.last_plot_time != sub.latest);
File
Create supabase/migrations/00009_reconcile_plot_counts.sql (check the latest migration number and increment).
Acceptance criteria
Context
PR #258 fixed the code path —
plot_countandlast_plot_timenow reconcile on every plot index and backfill. But existing storylines still have stale data from before the fix (e.g., storylines showingplot_count=1despite having 3+ plots chained).Task
Add a Supabase migration that reconciles all existing
storylines.plot_countandlast_plot_timefrom theplotstable.Migration SQL
File
Create
supabase/migrations/00009_reconcile_plot_counts.sql(check the latest migration number and increment).Acceptance criteria
npm run typecheckpasses