Safety Database Migration Rules
Never “Rename” or “Delete” in one step
Unsafe Example:
ALTER TABLE users RENAME COLUMN name TO full_name;
Safe Migration Steps
To rename or delete a column safely, follow these incremental steps:
- Safe Step 1: Add the new column
full_name. (Old code still uses name).
- Safe Step 2: Deploy code that writes to both columns but reads from the old one (
name).
- Safe Step 3: Migrate (Backfill) data from the old column
name to the new column full_name.
- Safe Step 4: Deploy code that reads from the new one (
full_name).
- Safe Step 5: (Weeks later) Delete the
name column.