Database Migrations Explained

Versioned, incremental schema changes that keep your database in sync with your code across all environments.

Database Migration

The process of making versioned, incremental changes to a database schema (adding tables, modifying columns, creating indexes) in a controlled and reversible manner.

Explanation

Database migrations solve the problem of evolving a database schema alongside application code. Each migration is a versioned script that applies a specific change (e.g., "add email_verified column to users table"). Migrations run in order, and the database tracks which have been applied. This ensures every environment (development, staging, production) has the same schema. Migrations should be backward-compatible in production to support zero-downtime deployments.

Bookuvai Implementation

Every Bookuvai project uses migration tools appropriate to the stack: Prisma Migrate for TypeScript/PostgreSQL, Mongoose migrations for MongoDB, and Knex for raw SQL projects. All migrations are code-reviewed, tested in staging, and deployed as part of the CI/CD pipeline.

Related Terms

Frequently Asked Questions

Can I roll back a migration?
Most migration tools support down/rollback scripts, but in practice, rolling forward (creating a new migration that fixes the issue) is safer and more common in production environments.
How do you handle migrations in production with zero downtime?
By making migrations backward-compatible. For example, to rename a column: first add the new column, deploy code that writes to both, migrate data, deploy code that reads from the new column, then remove the old column.