Skip to content
Dinvolt
Esc
↑↓navigate↵open⌘Jpreview
On this page

Database migrations

Change your schema

Use migrations for changes after the initial database setup.

1. Edit the schema

Add or update application tables in src/db/schema.ts. Export each table and include it in the existing schema object.

Keep the authentication exports from src/db/auth-schema.ts. PlanetScale also includes its relation exports; Turso configures relational queries with defineRelations(schema).

2. Generate SQL

npm run db:generate
bun run db:generate
pnpm run db:generate
yarn run db:generate

Open the new migration in drizzle/ and review its SQL before applying it.

3. Apply the migration

Development:

npm run db:migrate
bun run db:migrate
pnpm run db:migrate
yarn run db:migrate

Staging:

npm run db:migrate:staging
bun run db:migrate:staging
pnpm run db:migrate:staging
yarn run db:migrate:staging

Production:

npm run db:migrate:production
bun run db:migrate:production
pnpm run db:migrate:production
yarn run db:migrate:production

Confirm the target database and prepare a backup/recovery procedure before production changes. Apply migrations sequentially, outside deployment builds.

Commit the schema, drizzle/ directory, and .dinvolt/initial-database.json together. All environments share this migration directory; each database tracks its own applied migrations.

Inspect the database

Open Drizzle Studio for development:

npm run db:studio
bun run db:studio
pnpm run db:studio
yarn run db:studio

Check migration consistency without connecting to a database:

npm run db:check
bun run db:check
pnpm run db:check
yarn run db:check

Schema generation also works without a database connection. Studio and migration commands require credentials.

Was this page helpful?