class MigrationGraph:
Represent the digraph of all migrations in a project.
Each migration is a node, and each dependency is an edge. There are no implicit dependencies between numbered migrations - the numbering is merely a convention to aid file listing. Every new numbered migration has a declared dependency to the previous number, meaning that VCS branch merges can be detected and resolved.
Migrations files can be marked as replacing another set of migrations - this is to support the "squash" feature. The graph handler isn't responsible for these; instead, the code to load them in here should examine the migration files and if the replaced migrations are all either unapplied or not present, it should ignore the replaced ones, load in just the replacing migration, and repoint any dependencies that pointed to the replaced migrations to point to the replacing one.
A node should be a tuple: (app_path, migration_name). The tree special-cases things within an app - namely, root nodes and leaf nodes ignore dependencies to other apps.
Method | __contains__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | _generate_plan |
Undocumented |
Method | _nodes_and_edges |
Undocumented |
Method | add_dependency |
This may create dummy nodes if they don't yet exist. If skip_validation=True , validate_consistency() should be called afterward. |
Method | add_dummy_node |
Undocumented |
Method | add_node |
Undocumented |
Method | backwards_plan |
Given a node, return a list of which dependent nodes (dependencies) must be unapplied, ending with the node itself. This is the list you would follow if removing the migrations from a database. |
Method | ensure_not_cyclic |
Undocumented |
Method | forwards_plan |
Given a node, return a list of which previous nodes (dependencies) must be applied, ending with the node itself. This is the list you would follow if applying the migrations to a database. |
Method | iterative_dfs |
Iterative depth-first search for finding dependencies. |
Method | leaf_nodes |
No summary |
Method | make_state |
Given a migration node or nodes, return a complete ProjectState for it. If at_end is False, return the state before the migration has run. If nodes is not provided, return the overall most current project state. |
Method | remove_replaced_nodes |
Remove each of the replaced nodes (when they exist). Any dependencies that were referencing them are changed to reference the replacement node instead. |
Method | remove_replacement_node |
No summary |
Method | root_nodes |
Return all root nodes - that is, nodes with no dependencies inside their app. These are the starting point for an app. |
Method | validate_consistency |
Ensure there are no dummy nodes remaining in the graph. |
Instance Variable | node_map |
Undocumented |
Instance Variable | nodes |
Undocumented |
skip_validation=True
, validate_consistency() should be called
afterward.replaced
nodes (when they exist). Any
dependencies that were referencing them are changed to reference the
replacement
node instead.remove_replaced_nodes
. Almost. Remove the
replacement node replacement
and remap its child nodes to replaced
- the list of nodes it would have replaced. Don't remap its parent
nodes as they are expected to be correct already.