Appearance
Run Database Migrations
Manage Prisma migrations for local development and production.
Commands
| Command | When to use |
|---|---|
pnpm db:migrate | Apply pending migrations and generate the Prisma client (development) |
pnpm db:generate | Regenerate the Prisma client without running migrations |
pnpm db:reset | Drop the database, re-apply all migrations, and re-seed (destructive) |
pnpm db:studio | Open Prisma Studio to inspect the database |
Adding a model or field
- Edit or create the relevant
.prismafile inpackages/database/prisma/models/ - Run
pnpm db:migrate— Prisma will detect the diff and prompt you for a migration name - Enter a descriptive snake_case name (e.g.
add_note_content_index) - Prisma creates a migration file in
packages/database/prisma/migrations/and applies it
Writing a custom migration
If you need to run raw SQL (e.g. add an index, backfill data), create the migration manually:
bash
pnpm --filter @tt/database exec prisma migrate dev --name my_migration --create-onlyThis creates the migration file without applying it. Edit the generated SQL, then run:
bash
pnpm db:migrateProduction migrations
In production the API container runs prisma migrate deploy on startup. This applies all pending migrations without interactive prompts — it never creates new migrations.
WARNING
Never run prisma migrate dev in production. It is interactive and may prompt to reset the database.
After pulling changes with new migrations
Always run pnpm db:migrate after pulling commits that include new migration files. If you skip this and run the API, you will get runtime errors when it queries columns or tables that don't exist yet.