Skip to content

[chore] Add migration to reconcile stale plot_count data #259

@realproject7

Description

@realproject7

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

  • Migration file created with the reconciliation SQL
  • npm run typecheck passes
  • Idempotent — running the migration twice produces the same result

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/T3Assigned to T3 builder agentbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions