Published in 23:48 of 01/03/2013 by

Published in 23:48 of 01/03/2013

←Home

Programmatically check if Django South has migrations to run

Programmatically check if South has migrations to run.

from south import migration
from south.models import MigrationHistory

apps  = list(migration.all_migrations())

applied_migrations = MigrationHistory.objects.filter(app_name__in=[app.app_label() for app in apps])
applied_migrations = ['%s.%s' % (mi.app_name,mi.migration) for mi in applied_migrations]

num_new_migrations = 0
for app in apps:
    for migration in app:
        if migration.app_label() + "." + migration.name() not in applied_migrations:
            num_new_migrations = num_new_migrations + 1

return num_new_migrations

It can be wrapped in to a function and can be used to monitor South state in admin.

Based on south.management.commands.migrate and some C/P from stack overflow

  • App news reading (portuguese) in web2py · 20:08 of 09/11/2012
  • Lazy DAL - Attempt 3 - Pbreit in web2py · 14:27 of 08/15/2012
  • Open links which points outside your own site in a new window in python · 00:43 of 08/14/2012

  • comments powered by Disqus Go Top