Skip to content

Run Database Migrations

Manage Prisma migrations for local development and production.

Commands

CommandWhen to use
pnpm db:migrateApply pending migrations and generate the Prisma client (development)
pnpm db:generateRegenerate the Prisma client without running migrations
pnpm db:resetDrop the database, re-apply all migrations, and re-seed (destructive)
pnpm db:studioOpen Prisma Studio to inspect the database

Adding a model or field

  1. Edit or create the relevant .prisma file in packages/database/prisma/models/
  2. Run pnpm db:migrate — Prisma will detect the diff and prompt you for a migration name
  3. Enter a descriptive snake_case name (e.g. add_note_content_index)
  4. 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-only

This creates the migration file without applying it. Edit the generated SQL, then run:

bash
pnpm db:migrate

Production 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.

TT Time Tracker — Internal Documentation