class documentation

class MigrationGraph: (source)

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 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 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.
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 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.
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
Method _generate_plan Undocumented
Method _nodes_and_edges Undocumented
def __contains__(self, node): (source)

Undocumented

def __init__(self): (source)

Undocumented

def __repr__(self): (source)

Undocumented

def __str__(self): (source)

Undocumented

def add_dependency(self, migration, child, parent, skip_validation=False): (source)

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): (source)

Undocumented

def add_node(self, key, migration): (source)

Undocumented

def backwards_plan(self, target): (source)

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): (source)

Undocumented

def forwards_plan(self, target): (source)

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): (source)

Iterative depth-first search for finding dependencies.

def leaf_nodes(self, app=None): (source)

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): (source)

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): (source)

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): (source)

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): (source)

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): (source)

Ensure there are no dummy nodes remaining in the graph.

node_map: dict = (source)

Undocumented

Undocumented

def _generate_plan(self, nodes, at_end): (source)

Undocumented

def _nodes_and_edges(self): (source)

Undocumented