Public repository: timo / mitch

Reader

A migration stitcher (therefore mitch) for PostgreSQL, SQLite, MariaDB, and others

mitch / docs / adr / project / ordering-constraints-do-not-require.md · 1.7 KB · at 76a2c3d332a1 · raw


status: accepted

Ordering constraints order migrations without requiring them

Besides dependencies, a migration may declare after = [...]. Such a migration runs after the named ones whenever they are applied on the deployment or part of the same run; if they are neither, the constraint has no effect and they are not pulled in. This separates "must exist first" from "if it exists, go first", like Requires= and After= in systemd.

We needed it for reworks: the new version must run after everything that built on the previous version, so that fresh deployments get the same history as old ones, but turning those dependants into dependencies would roll out optional migrations nobody asked for. It is also useful on its own, for example for two migrations that both add values to the same enum and only need a fixed order between them.

Consequences

  • The run order is computed from dependencies plus the ordering constraints that are active on the deployment. A cycle among them is an error.
  • Ordering constraints do not count when mitch decides whether a migration is still needed by someone.
  • A migration named in an ordering constraint may arrive later than the migration that declared it, for example an optional dependant that a deployment only requests after a rework has run. By default mitch applies it anyway and warns that the order deviates from the graph. A flag restores the order instead: revert the later migration, apply the newcomer, re-apply, under the same safety rules as a rebuild. We chose the lenient default because enforcing the order would sneak a sequence back into what is meant to be a DAG, where installing optional migrations in any order is normal.