2 min read

How to do database migrations

Table of Contents

Migration Rules

ℹ️

Avoid breaking changes. Rollbacks must always work without requiring migration rollbacks.

  • Do not rename tables.
  • Do not rename columns.
  • Do not change column types.

How to Safely change table or column

  1. Create a new table or column.
  2. Start writing data to both the old and the new structure.
  3. Deploy the new version of the application and run the migration.
  4. Backfill existing data into the new structure before relying on it.
  5. Switch reads to use the new table or column.
  6. Deploy the updated version of the application.
  7. Remove the old table or column once it is no longer needed.