Database Migration
Definition
In software development, a database migration refers to the management of incremental, reversible changes to a relational database schema. Migrations are used to keep the database schema in sync with the application code.
Why It Matters
As an application evolves, its database schema needs to change (e.g., adding a new table or a new column). Migration tools provide a structured, version-controlled way to apply these changes, making it easy to update the database and roll back changes if something goes wrong.
Contextual Example
A developer needs to add a `last_login` column to the `users` table. They create a new migration file that contains the SQL `ALTER TABLE users ADD COLUMN last_login TIMESTAMP;`. They then run a migration tool which applies this change to the database and records that it has been run.
Common Misunderstandings
- Migration files are typically kept in source control along with the rest of the application code.
- This allows for automated and repeatable database deployments.