Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions supabase/migrations/00013_reconcile_plot_counts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Reconcile stale storylines.plot_count and last_plot_time from plots table.
-- Idempotent: only updates rows where values differ from computed aggregates.
-- Context: PR #258 fixed the code path; this migration fixes existing stale data.

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 IS DISTINCT FROM sub.cnt OR s.last_plot_time IS DISTINCT FROM sub.latest);
Loading