Feat/phase 2 backfill rooms to sessions

Closed
AH
5mo ago
+729-8
  • Introduced a new script "backfill:rooms-to-sessions" to facilitate the backfilling process.
  • Updated the "update-types" script for consistency.

Summary by cubic

Adds a Phase 2 backfill to migrate rooms into sessions, chats, and chat_messages. Preserves chat URLs, uses deterministic session IDs and stable pagination, and adds resilient message upserts. Run with pnpm backfill:rooms-to-sessions.

  • New Features

    • Added backfill:rooms-to-sessions script in package.json.
    • Migrates rooms → sessions, keeps rooms.id as chats.id, moves memories → chat_messages.
    • Paginated reads with secondary id ordering; deterministic session IDs (uuidv5).
    • Batch upserts for chat_messages with per-row retry; throws on count mismatches.
  • Refactors

    • Moved all Supabase queries to lib/supabase/<table>/* and shared paginate; migrateRoom + entry script are orchestration only.
    • Reuse serverClient; deleted duplicate backfill client.
    • Regenerated types/database.types.ts to include sessions, chats, chat_messages.
    • Runs via npx tsx; clearer errors; excluded scripts from TS build.

Summary by CodeRabbit

  • Chores
    • Added database helper utilities for managing chat messages, chats, sessions, and room data with conflict resolution handling
    • Implemented pagination support for efficient retrieval of large datasets

Review Change Stack