class MigrationLoader:
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 |
Undocumented
__first__
dependencies find the correct root node.