Created
May 15, 2017 22:54
-
-
Save alvinchow86/084ef47c4f68922c587bf1252e2d6d89 to your computer and use it in GitHub Desktop.
django-tips-blog-migration-manifest
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
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