Created
February 4, 2014 08:43
-
-
Save miraculixx/85c33dc7f7561b2e5fda to your computer and use it in GitHub Desktop.
Get latest django-south migrations per app
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 get_latest_migrations(): | |
""" | |
using South' MigrationHistory, get the latest migration id per app | |
using this, we can apply a --fake later on to get back the previous | |
state | |
""" | |
from south.models import MigrationHistory | |
from django.db.models.aggregates import Max | |
latest = MigrationHistory.objects.values('app_name').annotate(latest=Max('applied')) | |
migrations = {} | |
for l in latest: | |
m = MigrationHistory.objects.filter(app_name=l['app_name']).filter(applied=l['latest']) | |
mid = m[0].migration.split('_')[0] | |
migrations[l['app_name']] = mid | |
return migrations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment