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:generatebun run db:generatepnpm run db:generateyarn run db:generateOpen the new migration in drizzle/ and review its SQL before applying it.
3. Apply the migration
Development:
npm run db:migratebun run db:migratepnpm run db:migrateyarn run db:migrateStaging:
npm run db:migrate:stagingbun run db:migrate:stagingpnpm run db:migrate:stagingyarn run db:migrate:stagingProduction:
npm run db:migrate:productionbun run db:migrate:productionpnpm run db:migrate:productionyarn run db:migrate:productionConfirm 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:studiobun run db:studiopnpm run db:studioyarn run db:studioCheck migration consistency without connecting to a database:
npm run db:checkbun run db:checkpnpm run db:checkyarn run db:checkSchema generation also works without a database connection. Studio and migration commands require credentials.