Add a graph for managing dependencies between evolutions and migrations.
Review Request #11231 — Created Oct. 19, 2020 and submitted
This introduces two new classes:
DependencyGraph
andEvolutionGraph
.
DependencyGraph
is 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
past.
EvolutionGraph
specializes 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 switchEvolver
over to using the graph to apply
evolutions and migrations in the correct order.
Unit tests pass on all supported versions of Python and Django.
Summary | ID |
---|---|
f5846d8506fefe49d5bce93adb91cb984ee445a5 |
Description | From | Last Updated |
---|---|---|
F841 local variable 'migrations_app' is assigned to but never used |
reviewbot | |
F841 local variable 'migrations_app2' is assigned to but never used |
reviewbot | |
F401 'collections.OrderedDict' imported but unused |
reviewbot | |
Maybe say set of Node here like you do for dependencies? |
david |
- Change Summary:
-
- Removed unused variables and imports.
- Defaulted the graph's processing of migration dependencies based on the
supports_migrations
flag. - Improved some assertion error messages, to aid debugging.
- Commits:
-
Summary ID ad2b27f461c65b86bdf742f4310eac116d9a618b f5846d8506fefe49d5bce93adb91cb984ee445a5 - Diff:
-
Revision 2 (+3468 -6)