All twenty problems
D10What it costs the developer

A schema change on production, with no way back.

Adding a column is the easy half. The missing half is the record: which statements in that run actually applied, and what undoes them.

What actually goes wrong

A migration that fails on statement four leaves a database in a state no version of the code expects. Without a record of what applied, recovery is somebody reading SQL at midnight and guessing.

The forward migration is the part everybody writes. The run identifier, the rollback and the refusal to do something unsafe are the parts that are missing when it matters.

What Grit does about it

  • Each migration run has an identifier and a record of the statements that applied, so a failed run can be reversed rather than reconstructed.
  • A change that would lose data is refused rather than performed, and says what it would have dropped.
  • Backup and restore are commands, so the state before a migration is recoverable.

The commands

grit migrate
What ran, and what it would take back
grit migrate status
grit migrate down
Before anything irreversible
grit backup

What it does not do

A rollback restores schema, not meaning. A migration that rewrote values on the way through needs a data migration to reverse it, and the framework cannot invent one.

Read next