feat: catalog_valuations — persisted valuation history (chat#1889 row 15)

Merged
SW
4mo ago
+35-0

Database leg of row 15, the keystone on chat#1889. Merge order: docs#279 → this → api#TBD.

catalog_valuations: one row per band computation — catalog_id (FK CASCADE), low/mid/high (USD), measured_song_count, total_streams, measured_at — with a (catalog_id, measured_at DESC) index matching the only read shape (latest-first per catalog). History table by design, never columns on catalogs: the whole point is two numbers to compare.

Writers land in the api PR: runValuationHandler (always) + the measurements read path (at most one row per catalog per day). Schema-only migration — no data touched; trivially fresh-env safe.

🤖 Generated with Claude Code


Summary by cubic

Add persisted valuation history per catalog via a new catalog_valuations table so we can compare values over time (chat#1889, row 15). Optimized for latest‑first reads; writers will be added in the API follow-up.

  • New Features

    • Adds catalog_valuations with: catalog_id, low/mid/high (USD), measured_song_count, total_streams, measured_at, created_at.
    • FK to catalogs with ON DELETE CASCADE.
    • Index on (catalog_id, measured_at DESC) for efficient latest-first queries.
  • Migration

    • Schema-only; no data touched and safe on fresh environments.

Summary by CodeRabbit

  • New Features
    • Added persistent valuation history for catalogs.
    • Valuation records now capture low, mid, and high estimates, song counts, total streams, and measurement timestamps.
    • Catalog valuation history is automatically cleaned up when its associated catalog is deleted.