Add a graph for managing dependencies between evolutions and migrations.
Review Request #11231 — Created Oct. 19, 2020 and submitted
This introduces two new classes:
DependencyGraphis a generic class for managing dependencies between
nodes and returning an order using a topological sort. Each node
stores a key, an insertion order (the order in which it was added
to the graph), a dictionary of state, and lists of nodes that it depends
on or that depend on it.
Dependencies are lazily-added through the graph, and can be removed.
When all manipulations of the graph are complete, a caller will call
finalize()to record dependencies, validate the graph, and allow
fetching the sorted order of nodes.
The previously-mentioned insertion order is an important implementation
detail in this graph. These work as a sort of loose dependency between
nodes. If two nodes don't define explicit dependencies to specify their
order, the insertion order will be used. This helps keep the order
generally consistent with the evolution ordering that we've used in the
EvolutionGraphspecializes this to manage dependencies
between evolutions, migrations, and model creations. An entire list of
evolutions and model creations for an app can be added at once, or an
entire migration plan. The graph will take care of determining the
correct dependencies for these and apply them. It then allows the caller
to retrieve batches of evolutions/migrations/model creations, grouped by
type and in the order indicated by dependencies.
As of this change, the graph isn't used outside of unit tests. Upcoming
changes will switch
Evolverover to using the graph to apply
evolutions and migrations in the correct order.
Unit tests pass on all supported versions of Python and Django.
F841 local variable 'migrations_app' is assigned to but never used
F841 local variable 'migrations_app2' is assigned to but never used
F401 'collections.OrderedDict' imported but unused
Maybe say set of Node here like you do for dependencies?
- Removed unused variables and imports.
- Defaulted the graph's processing of migration dependencies based on the
- Improved some assertion error messages, to aid debugging.
Revision 2 (+3468 -6)