statenour-migration
Use when changing the statenour Prisma schema (apps/statenour/prisma/schema.prisma) — migrations are hand-applied and one wrong flag silently drops pgvector data.
SKILL.md.claude/skills/statenour-migration/SKILL.md
GitHubstatenour-migration
statenour's Prisma migrations are NOT auto-applied. A schema change needs a deliberate, prod-verified apply.
Hard rules
- NEVER
prisma db push --accept-data-loss— and never put that flag in apackage.jsonscript or CI. pgvector (vector_embeddings.embedding_vec*) and thechat_messagestsvector generated column live partly outside Prisma's model view;--accept-data-losssilently drops them. A pre-push gate guards against this — don't defeat it. Recovery isscripts/recover-pgvector-*.ts. prisma migrate statusagainst prod Neon is the source of truth — not "I ran release:db". Local success messaging can lie when the prod DB is unreachable or auth fails silently (the v10.0.473 incident).- Nothing auto-records the ledger any more. The guarded endpoint
POST /api/system/apply-pending-migrationapplies its registry DDL but deliberately does not write_prisma_migrations(#1231). Hand- inserted rows for names with noprisma/migrations/<name>/dir are what turnedmigrate statusred in the first place — 9 orphan rows deleted 2026-07-30. Recording is always: promote the SQL intoprisma/migrations/<name>/, thenprisma migrate resolve --applied. - A deliberate DROP must also prune every re-apply path. Removing a
table means removing its endpoint registry entry, its one-shot apply
scripts, and any parked SQL — otherwise
IF NOT EXISTSmachinery quietly resurrects it. Found live 2026-07-30 (#1233): a registry entry would have re-created three tables retired weeks earlier.
Workflow
- Edit
prisma/schema.prisma. - Generate the migration SQL; park it under
prisma/migrations-pending/if prod connectivity isn't confirmed yet. - Apply with
scripts/apply-pending-migration.ts— it uses an autocommit pg driver, required forCREATE INDEX CONCURRENTLY(which cannot run inside Prisma's implicit transaction wrap). - Record it:
prisma migrate resolve --applied <name>. - Confirm:
prisma migrate statusshows clean. pnpm typecheck— the generated client changed.- Add the directory name to
lib/db/migration-manifest.ts(tests/lib/system/owner-panel-migrations.test.tsfails until you do). The Owner Panel pagesmigration_unappliedfor any manifest name prod's_prisma_migrationslacks — committing a migration is not applying it:20260929123500_reality_event_envelopesat committed-but-unapplied for three days (2026-09-29..10-02) while everyreality_eventswrite failed.
When NOT to use
nickstire migrations — different conventions (hand-applied SQL in
apps/nickstire/drizzle/NNNN_*.sql, no Prisma).