Unsafe Example:
ALTER TABLE users RENAME COLUMN name TO full_name;To rename or delete a column safely, follow these incremental steps:
- Safe Step 1: Add the new column
full_name. (Old code still usesname). - 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
nameto the new columnfull_name. - Safe Step 4: Deploy code that reads from the new one (
full_name). - Safe Step 5: (Weeks later) Delete the
namecolumn.