Skip to content

Instantly share code, notes, and snippets.

@alvinchow86
Created May 15, 2017 22:54
Show Gist options
  • Save alvinchow86/084ef47c4f68922c587bf1252e2d6d89 to your computer and use it in GitHub Desktop.
Save alvinchow86/084ef47c4f68922c587bf1252e2d6d89 to your computer and use it in GitHub Desktop.
django-tips-blog-migration-manifest
def handle(self, *app_labels, **options):
# Generate a migrations manifest with latest migration on each app
super(Command, self).handle(*app_labels, **options)
loader = MigrationLoader(None, ignore_no_migrations=True)
apps = sorted(loader.migrated_apps)
graph = loader.graph
with open('latest_migrations.manifest', 'w') as f:
for app_name in apps:
leaf_nodes = graph.leaf_nodes(app_name)
if len(leaf_nodes) != 1:
raise Exception('App {} has multiple leaf migrations!'.format(app_name))
f.write('{}: {}\n'.format(app_name, leaf_nodes[0][1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment