Show Menu
Cheatography

Database Migrations Cheat Sheet (DRAFT) by

Cheatsheet for zero-downtime DB Migrations

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Good things, easy to do

Add a new column
Drop a column
Add an index concur­rently (
LOCK=NONE
, may or may not work)
Drop a constraint (for example, non-nu­llable)
Add a default value to an existing column (again,
LOCK=NONE
)
 

Changing Column Type

Add migration to create new temporary column with wanted type
Ship that migration
Add trigge­r/code path to write to both columns
Ship that code
Add migration to copy data in chunks from old column to new one
Ship that migration
Add migration to rename temporary column