🗃️Database Migration
Also known as Schema Migration, Migration, Migration File
A small file that makes one change to a database's shape. It lives with the code.
Think of it like
Think of it like a list of steps to rearrange a room. Anyone can follow it and end up with the same room.
Example
Jack adds a phone field to his app. He writes a migration, and when he deploys, the live database gets the new column too.
Why it matters
Without migrations, each copy of the database drifts. Then code that works on your laptop breaks on the server.
Definition
Example code
sql
-- 0007_add_phone.sql
ALTER TABLE customers ADD COLUMN phone TEXT;Common mistake
Key takeaways
- 1One step each. Small changes, in order.
- 2Kept in Git. Next to the code that needs them.
- 3Never edit old ones. Add a new step instead.