Public repository: timo / mitch

Reader

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

mitch / docs / adr / runner / deployments-record-the-applied-dependency-graph.md · 2.4 KB · at 76a2c3d332a1 · raw


status: accepted

Deployments record the applied dependency graph

Besides which migrations are applied, a deployment stores their dependency edges ("a:x depends on u:y"). This is what lets mitch answer "does anyone still need this migration?" when several projects, loaded or not, share migrations of a linked project. A record of applied migrations without edges could not answer it.

The edges are a cache of the source code, not a history:

  • An edge belongs to the project of the dependant. Every run that loads a project refreshes the edges of that project's applied migrations from the source. Edges of projects that are not loaded stay as last written.
  • A removed dependency disappears silently on the next run.
  • An added dependency on a migration that is not applied makes the dependant count as modified, so the --if-modified policy decides. The flag --late-dependencies on up and add instead applies the new dependency late and keeps the dependant, with a warning that the order deviates from the graph.
  • A run that cannot load every linked project does not refresh edges, because unresolved references would look like removed dependencies.

Besides the edges, a deployment records which migrations were pulled in, that is applied only as a dependency of another project's migration. Only those can become orphaned. Without this record, down in one project would treat a linked project's migrations that the linked project applied for its own sake as orphans, since they have no dependants either. A redeploy keeps a migration's record as requested or pulled in.

Consequences

  • Migrations of a linked project reach a deployment only as dependencies of the project's own migrations. add accepts only own migrations; drop accepts foreign ones too.
  • down and drop also revert linked-project migrations that become orphaned, so down restores the deployment to what it was before up.
  • A revert is refused when an applied dependant belongs to a project that is not loaded, because its down script is unknown. This holds for every command that reverts: drop, down, redeploys in up and add, checkout and stash. The error names the blocking projects. There is no --force.
  • missing is reported only for the project's own migrations. A linked-project migration that is applied but absent from the local copy may come from another consumer's newer copy.