What are database migrations and how do tools like Flyway or Liquibase work?
Short answer
A migration is a versioned script that changes the database schema (create table, add column, add index). Tools like Flyway and Liquibase apply migrations in order, exactly once, and record which ones ran in a history table — so every environment's database ends up with the same schema as the code expects.
Flyway example
src/main/resources/db/migration/
V1__create_orders.sql
V2__add_status_column.sql
V3__create_index_customer.sql
-- V2__add_status_column.sql
ALTER TABLE orders ADD COLUMN status VARCHAR(20) DEFAULT 'NEW';
flyway -url=jdbc:postgresql://db:5432/orders -user=migrator -password=*** migrate
flyway info # what's applied, what's pending
Flyway stores applied versions and checksums in flyway_schema_history. Editing an already-applied file changes its checksum and Flyway refuses to continue — migrations are append-only.
Liquibase
Changelogs in SQL/XML/YAML, supports rollback definitions and contexts per environment.
Other stacks
Alembic (Python/SQLAlchemy), Django migrate, EF Core dotnet ef database update, Prisma/Knex (Node).
What to say in the interview
"Migrations version the schema alongside code. Flyway applies V1, V2… in order once and tracks them with checksums in a history table, so every environment converges to the same schema. Applied migrations are immutable — fixes go in a new migration."