pub struct DependencyGraph { /* private fields */ }Expand description
A directed acyclic graph of migration dependencies.
Implementations§
Source§impl DependencyGraph
impl DependencyGraph
Sourcepub fn build(
migrations: &[&ResolvedMigration],
implicit_chain: bool,
) -> Result<Self>
pub fn build( migrations: &[&ResolvedMigration], implicit_chain: bool, ) -> Result<Self>
Build a dependency graph from resolved migrations.
If implicit_chain is true, each versioned migration implicitly depends
on the previous version in sort order (backward-compatible default).
Sourcepub fn topological_sort(&self) -> Result<Vec<String>>
pub fn topological_sort(&self) -> Result<Vec<String>>
Produce a topologically sorted order of versions using Kahn’s algorithm.
Ties — migrations that become runnable at the same moment — are broken by version order, which makes the result deterministic.
This matters more than it looks. The ready set used to be a VecDeque
fed from reverse_edges, a HashSet whose iteration order is randomly
seeded per process. Five independent migrations therefore applied in a
different order on almost every run: the order explain previewed was
not the order migrate used, and staging and production disagreed on
installed_rank. Any topological order is correct, but only a
reproducible one is honest.
Uses borrowed &str references internally to avoid cloning during
the sort; only clones into owned Strings for the output.