Development
What is a database migration and how should you manage them?
A database migration is a versioned, incremental change to your database schema (adding tables, columns, indexes) tracked in code alongside your application. Migrations run in order during deployment to keep the database in sync with application code. Use a migration tool (Prisma Migrate, Drizzle Kit, Flyway, Alembic) that generates timestamped migration files and tracks which have been applied.
Key Considerations
- Every schema change must be a migration — never modify production databases manually
- Write both "up" and "down" migrations so you can roll back failed deployments
- Test migrations against a copy of production data before deploying — empty-table migrations often hide issues
- For zero-downtime deployments, use expand-and-contract: add the new column first, deploy code that writes to both, then remove the old column
- Keep migrations small and focused — one concern per migration file makes debugging easier