FluxyChat

Operations

D1 schema consolidation plan (P21)

FluxyChat currently ships 136 sequential migrations under `apps/worker/db/` (0001–0136). P15–P20 added many feature-specific tables. This document defin

FluxyChat currently ships 136 sequential migrations under apps/worker/db/ (0001–0136). P15–P20 added many feature-specific tables. This document defines a safe consolidation strategy without blocking current deploys.

Goals

  1. Faster fresh installs -- one baseline snapshot for new environments instead of 136 ALTER steps.
  2. Clear domain boundaries -- group tables by feature area for docs and access reviews.
  3. No production downtime -- consolidation is additive; old migration history stays valid.

Current shape (high level)

DomainExample migrationsNotes
Core chat0001–0011, 0005, 0007messages, threads, reactions, tenancy
Agents & AI0010, 0013, 0060–0063, 0086agents, runs, memory, knowledge graph
Omnichannel0054–0057, 0079–0080telco, inbox, quiet hours
Enterprise0082, 0113–0117, 0129–0136retention, IP whitelist, eDiscovery, SSO
Integrations0124–0125, 0119bridges, marketplace
Ops0014–0016, 0105metrics, alerts, rate-limit dashboard

Phase 1 -- Inventory (done in repo)

  • Keep applying migrations 0001→0136 on existing DBs (your deploy flow).
  • Feature map: docs/features-overview.md P21 table.

Phase 2 -- Baseline snapshot

  1. On a fresh local D1, apply all migrations.
  2. Export schema (no data) to apps/worker/db/baseline/0136_schema.sql.
  3. Use apps/worker/db/README.md for greenfield vs incremental guidance.
cd apps/worker
wrangler d1 migrations apply fluxychat --local
pnpm run db:export-baseline
# Writes db/baseline/0136_schema.sql (wrangler d1 export fails on FTS5 virtual tables)

Phase 3 -- View layer (optional)

Create SQL views for cross-feature queries (e.g. v_project_compliance joining audit + retention) without merging tables.

Phase 4 -- Deprecation pass (post GA)

  • Identify duplicate concepts (e.g. overlapping moderation tables from P12 vs P15).
  • Mark deprecated columns with migration comments; remove only after one release cycle.

What we are not doing yet

  • Merging live tables in production in one shot.
  • Changing project_plans or quota columns without a Stripe migration plan.
  • Squashing git history of old migration files (breaks existing deploy hashes).

Operator checklist (when you run migrations)

cd apps/worker
wrangler d1 migrations list fluxychat --remote
wrangler d1 migrations apply fluxychat --remote
# Verify
wrangler d1 execute fluxychat --remote --command "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"
  • @fluxy-chat/protocol -- shared WS event registry (SDK + worker)
  • packages/protocol/protocol-events.json -- cross-SDK manifest (Flutter, RN, TS)
  • Observability: observability.md

On this page