class documentation

class MigrationLoader:

View In Hierarchy

Load migration files from disk and their status from the database.

Migration files are expected to live in the "migrations" directory of an app. Their names are entirely unimportant from a code perspective, but will probably follow the 1234_name.py convention.

On initialization, this class will scan those directories, and open and read the Python files, looking for a class called Migration, which should inherit from django.db.migrations.Migration. See django.db.migrations.migration for what that looks like.

Some migrations will be marked as "replacing" another set of migrations. These are loaded into a separate set of migrations away from the main ones. If all the migrations they replace are either unapplied or missing from disk, then they are injected into the main set, replacing the named migrations. Any dependency pointers to the replaced migrations are re-pointed to the new migration.

This does mean that this class MUST also talk to the database as well as to disk, but this is probably fine. We're already not just operating in memory.

Class Method migrations​_module Return the path to the migrations module for the specified app_label and a boolean indicating if the module is specified in settings.MIGRATION_MODULE.
Method __init__ Undocumented
Method add​_external​_dependencies Undocumented
Method add​_internal​_dependencies Internal dependencies need to be added first to ensure __first__ dependencies find the correct root node.
Method build​_graph Build a migration dependency graph using both the disk and database. You'll need to rebuild the graph if you apply migrations. This isn't usually a problem as generally migration stuff runs in a one-shot process.
Method check​_consistent​_history Raise InconsistentMigrationHistory if any applied migrations have unapplied dependencies.
Method check​_key Undocumented
Method collect​_sql Take a migration plan and return a list of collected SQL statements that represent the best-efforts version of that plan.
Method detect​_conflicts Look through the loaded graph and detect any conflicts - apps with more than one leaf migration. Return a dict of the app labels that conflict with the migration names that conflict.
Method get​_migration Return the named migration or raise NodeNotFoundError.
Method get​_migration​_by​_prefix Return the migration(s) which match the given app label and name_prefix.
Method load​_disk Load the migrations from all INSTALLED_APPS from disk.
Method project​_state Return a ProjectState object representing the most recent state that the loaded migrations represent.
Instance Variable applied​_migrations Undocumented
Instance Variable connection Undocumented
Instance Variable disk​_migrations Undocumented
Instance Variable graph Undocumented
Instance Variable ignore​_no​_migrations Undocumented
Instance Variable migrated​_apps Undocumented
Instance Variable replace​_migrations Undocumented
Instance Variable replacements Undocumented
Instance Variable unmigrated​_apps Undocumented
@classmethod
def migrations_module(cls, app_label):
Return the path to the migrations module for the specified app_label and a boolean indicating if the module is specified in settings.MIGRATION_MODULE.
def __init__(self, connection, load=True, ignore_no_migrations=False, replace_migrations=True):

Undocumented

def add_external_dependencies(self, key, migration):

Undocumented

def add_internal_dependencies(self, key, migration):
Internal dependencies need to be added first to ensure __first__ dependencies find the correct root node.
def build_graph(self):
Build a migration dependency graph using both the disk and database. You'll need to rebuild the graph if you apply migrations. This isn't usually a problem as generally migration stuff runs in a one-shot process.
def check_consistent_history(self, connection):
Raise InconsistentMigrationHistory if any applied migrations have unapplied dependencies.
def check_key(self, key, current_app):

Undocumented

def collect_sql(self, plan):
Take a migration plan and return a list of collected SQL statements that represent the best-efforts version of that plan.
def detect_conflicts(self):
Look through the loaded graph and detect any conflicts - apps with more than one leaf migration. Return a dict of the app labels that conflict with the migration names that conflict.
def get_migration(self, app_label, name_prefix):
Return the named migration or raise NodeNotFoundError.
def get_migration_by_prefix(self, app_label, name_prefix):
Return the migration(s) which match the given app label and name_prefix.
def load_disk(self):
Load the migrations from all INSTALLED_APPS from disk.
def project_state(self, nodes=None, at_end=True):

Return a ProjectState object representing the most recent state that the loaded migrations represent.

See graph.make_state() for the meaning of "nodes" and "at_end".

applied_migrations: dict =

Undocumented

connection =

Undocumented

disk_migrations: dict =

Undocumented

graph =

Undocumented

ignore_no_migrations =

Undocumented

migrated_apps: set =

Undocumented

replace_migrations =

Undocumented

replacements: dict =

Undocumented

unmigrated_apps: set =

Undocumented