What is Schema migration?
A schema migration is a versioned, repeatable change to a database's structure, adding a column, creating an index, backfilling data, applied in order so every environment converges on the same schema.
A schema migration is a discrete, ordered change to the shape of a database: adding or dropping columns, creating tables or indexes, changing types, or backfilling data to fit a new structure. Migrations are kept as version-controlled files (each one forward and ideally reversible) and applied in sequence by a migration tool such as Prisma Migrate, Flyway, Alembic, or Rails migrations, so that a fresh database and a years-old production database both arrive at exactly the same schema by replaying the same history. This discipline solves a brutal problem: code expects a certain database shape, and the two must change together across many environments and many developers without drift. The dangerous migrations are the ones that lock tables, rewrite large amounts of data, or change a column the running application still reads, so safe practice favors additive, backward-compatible steps (expand-then-contract) that can be deployed without downtime. Migrations interact closely with deployments: a release often pairs a migration with code that depends on it. For an AI agent working in a codebase, the migration history, pending migrations, and which columns are mid-transition are precisely the kind of fast-moving structural knowledge that a shared memory layer can carry between sessions so the agent does not propose a change that conflicts with an in-flight migration.