Database migrations version-control your schema, enabling team collaboration and safe deployments. They track every change to tables, indexes, and constraints.
Prisma Migrate (Node.js): define schema in schema.prisma, run prisma migrate dev to generate SQL. Prisma handles rollbacks and seeding.
Flyway and Liquibase are database-agnostic tools. They support SQL migrations and provide rollback capabilities.
Best practices: never modify a deployed migration. Create new migrations for changes. Test migrations on a copy of production data. Separate schema changes from data migrations.
Down migrations: always write the reverse operation. ALTER TABLE ADD COLUMN becomes ALTER TABLE DROP COLUMN. This enables safe rollbacks.
Zero-downtime migrations: add columns as nullable first, backfill data, then add constraints. Use online schema change tools for large tables.
CI/CD integration: run migrations automatically in deployment pipelines. Verify they succeed before deploying application code.