Created
July 12, 2016 14:59
-
-
Save simonhayward/428a18c2357042d46781ab6b8b788075 to your computer and use it in GitHub Desktop.
Check migrations ran
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from django.db import DEFAULT_DB_ALIAS, connections | |
from django.db.migrations.loader import MigrationLoader | |
def migrations_have_applied(): | |
""" | |
Check if there are any migrations that haven't been applied yet | |
""" | |
connection = connections[DEFAULT_DB_ALIAS] | |
loader = MigrationLoader(connection) | |
graph = loader.graph | |
# Count unapplied migrations | |
num_unapplied_migrations = 0 | |
for app_name in loader.migrated_apps: | |
for node in graph.leaf_nodes(app_name): | |
for plan_node in graph.forwards_plan(node): | |
if plan_node not in loader.applied_migrations: | |
num_unapplied_migrations += 1 | |
return num_unapplied_migrations == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment