# Reversible migrations

A step of the [Cloud application](https://gradus.kazet.blog/tree/cloud-application) tree on Gradus, in the Build & ship area: Config, lint, releases, IaC.

Page: https://gradus.kazet.blog/tree/cloud-application/step/reversible-migrations

Change the data in stages that keep the previous release working: expand, backfill, then contract in a later release, so a rollback never meets a schema it cannot read.

Usually comes after: [One-command rollback](https://gradus.kazet.blog/tree/cloud-application/step/rollback).

Leads to: [Blue-green releases](https://gradus.kazet.blog/tree/cloud-application/step/blue-green-releases).

## Prompt for your AI assistant

```
Read the database decision record in docs/decisions and this service's migrations or data model. Write the expand and contract rule into docs/: a breaking change ships as an additive change, a release that handles both shapes, a backfill and a later release that removes the old shape. Where the database has migration files, add a CI check that fails on a destructive change in the same release as the code that stops using it. Then rename one real field this way, deploying after every stage and rolling back once to prove the previous release still works.
```

Every step of the tree: https://gradus.kazet.blog/tree/cloud-application/llms.txt
