class documentation

class MigrationGraph:

View In Hierarchy

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
def __contains__(self, node):

Undocumented

def __init__(self):

Undocumented

def __repr__(self):

Undocumented

def __str__(self):

Undocumented

def _generate_plan(self, nodes, at_end):

Undocumented

def _nodes_and_edges(self):

Undocumented

def add_dependency(self, migration, child, parent, skip_validation=False):
This may create dummy nodes if they don't yet exist. If skip_validation=True, validate_consistency() should be called afterward.
def add_dummy_node(self, key, origin, error_message):

Undocumented

def add_node(self, key, migration):

Undocumented

def backwards_plan(self, target):
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.
def ensure_not_cyclic(self):

Undocumented

def forwards_plan(self, target):
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.
def iterative_dfs(self, start, forwards=True):
Iterative depth-first search for finding dependencies.
def leaf_nodes(self, app=None):
Return all leaf nodes - that is, nodes with no dependents in their app. These are the "most current" version of an app's schema. Having more than one per app is technically an error, but one that gets handled further up, in the interactive command - it's usually the result of a VCS merge and needs some user input.
def make_state(self, nodes=None, at_end=True, real_apps=None):
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.
def remove_replaced_nodes(self, replacement, replaced):
Remove each of the replaced nodes (when they exist). Any dependencies that were referencing them are changed to reference the replacement node instead.
def remove_replacement_node(self, replacement, replaced):
The inverse operation to 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.
def root_nodes(self, app=None):
Return all root nodes - that is, nodes with no dependencies inside their app. These are the starting point for an app.
def validate_consistency(self):
Ensure there are no dummy nodes remaining in the graph.
node_map: dict =

Undocumented

nodes: dict =

Undocumented