Knowledgebase

Handling Database Changes in Version Control Print

  • devopsinfrastructure, devops, database, migration, backup, troubleshooting, guide, howto
  • 0

Schema as part of the code.

THE PROBLEM

Code is versioned. Databases are not, unless you make them so.

WHAT THAT PRODUCES

Code expecting a column that does not exist Environments with different structures Nobody able to recreate the database

WHAT TO DO

Describe every structural change as a migration, committed alongside the code.

WHAT EACH MIGRATION NEEDS

How to apply it, and how to reverse it.

WHAT TO NEVER DO

Change a migration that has already run in production.

WHY

The record of what was applied becomes wrong, and environments diverge.

WHAT TO DO INSTEAD

Write a new migration.

WHAT TO BE CAREFUL WITH

Migrations that lock large tables Migrations combining structural and data changes

WHAT TO SEPARATE

Structure from data.

WHAT TO RUN BEFORE MIGRATING PRODUCTION

A backup.

WHAT TO TEST

Applying and reversing, on a copy with realistic volume.

WHAT TO ORDER CAREFULLY

Deployments involving both code and schema changes.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot