Migration
In one line
A migration is a script that modifies the database schema — creating tables, adding columns, etc. — tracked in version control.
In simple words
A migration is a script that changes the database schema. Instead of manually editing tables in production, you write migration scripts that are version-controlled and applied in order.
A typical migration system has "up" and "down" scripts:
- Up: applies the change (e.g., adds a column).
- Down: reverses the change (e.g., drops the column).
Migrations are tracked in a special table so the system knows which ones have been applied. This lets you:
- Reproduce the database schema in any environment.
- Roll back changes if something goes wrong.
- Collaborate on schema changes through version control.
Tools like Flyway, Liquibase, Alembic, and Prisma Migrate manage migrations for various languages and frameworks.
Example
-- Migration 003: add phone column to users
-- Up
ALTER TABLE users ADD COLUMN phone TEXT;
-- Down
ALTER TABLE users DROP COLUMN phone;A migration adds a phone column. The down migration reverses it by dropping the column.
Related terms
Related Resources
Related Lessons
- Migrations
Learn how to manage schema changes with migrations.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.