Skip to content

migrations: Add additional graph utils

Warren Gifford requested to merge ef/migration-definition-utils into main

Created by: efritz

Pulled from #29831. This PR adds additional methods onto Definitions, which is a topologically ordered sequence of migrations. Currently, we only construct linear chains of migrations.

These new methods are preparing for a world where we construct something cooler:

  • All returns all migrations.
  • Root returns the migration with no defined parent.
  • Leaves returns migrations with no defined children. These are the migrations that should be the parents of newly defined migrations. These are also the set of migration targets we can plug into Up (see below) to build the set of migrations which need to be applied on upgrade.
  • Filter induces a migration subgraph to what it looked like in for a historic commit. This will be useful for squashing old migrations. See LeafDominator, which is also related to squashing.
  • LeafDominator returns the most specific common dominator of the leaves. When squashing, we need to select an old commit that we know has been applied on all upgrade paths, and we also need to make sure that the migrations we squash form a single-entry, single-exit graph. This dominator gives exactly these properties.
  • Up and Down returns some filtered subset of definitions that are descendants or ancestors (respectively) of the the target commit on migration operations. This will be used in place of {Up,Down}{To,From} methods that compose our current CLI tooling.

Reviewers: Each new method (and test) is added in separate commits for cohesion.

Merge request reports

Loading