• 
      

    Add a graph for managing dependencies between evolutions and migrations.

    Review Request #11231 — Created Oct. 19, 2020 and submitted — Latest diff uploaded

    Information

    Django Evolution
    master

    Reviewers

    This introduces two new classes: DependencyGraph and EvolutionGraph.

    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 switch Evolver 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.

    Commits

    Files