jdunck avatar jdunck committed 515423b

migrationcheck command to clarify missing depends_on.

Comments (0)

Files changed (1)

south/management/commands/migrationcheck.py

+from django.core.management import call_command
+from django.core.management.base import BaseCommand
+from django.conf import settings
+from django.db.models import loading
+from django.test import simple
+
+from south.migration import Migrations
+from south.exceptions import NoMigrations
+from south.hacks import hacks
+
+class Command(BaseCommand):
+    help = "Runs migrations for each app in turn, detecting missing depends_on values."
+    usage_str = "Usage: ./manage.py migrationcheck"
+
+    def handle(self, **options):
+        runner = simple.DjangoTestSuiteRunner(verbosity=0)
+        err_msg = "Failed to migrate %s; see output for hints at missing dependencies:"
+        hacks.patch_flush_during_test_db_creation()
+        for app_name in settings.INSTALLED_APPS:
+            app_label = app_name.split(".")[-1]
+            if app_name == 'south':
+                continue
+
+            try:
+                Migrations(app_name)
+            except NoMigrations:
+                continue
+            app = loading.get_app(app_label)
+            print "processing %s" % app_name
+
+            old_config = runner.setup_databases()
+            try:
+                call_command('migrate', app_label, noinput=True, verbosity=0)
+                for model in loading.get_models(app):
+                    dummy = model._default_manager.exists()
+            except (KeyboardInterrupt, SystemExit):
+                raise
+            except Exception, e:
+                print err_msg % app_name
+                print e
+
+            finally:
+                runner.teardown_databases(old_config)
+#
+#for each app:
+#    start with blank db.
+#    syncdb only south (and contrib?)
+#
+#    migrate a single app all the way up.  any errors is missing depends_on.
+#    for all models of that app, try the default manager:
+#        from django.db.models import loading
+#        for m in loading.get_models(loading.get_app('a')):
+#            m._default_manager.exists()
+#    Any error is also a missing depends on.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.