Simon Law avatar Simon Law committed 3428bb5

Remove find_ghost_migrations() and currently_applied()

Comments (0)

Files changed (1)

south/migration/__init__.py

                     problems.append((migration, m))
     return problems
 
-def find_ghost_migrations(histories):
-    result = []
-    for history in histories:
-        migration = history.get_migration()
+def check_migration_histories(histories):
+    exists = []
+    ghosts = []
+    migrations = (h.get_migration() for h in histories)
+    for m in migrations:
         try:
-            migration.migration()
+            m.migration()
         except exceptions.UnknownMigration:
-            result.append(migration)
-    return result
-
-def check_migration_histories(histories):
-    ghosts = find_ghost_migrations(histories)
+            ghosts.append(m)
+        except ImproperlyConfigured:
+            pass                        # Ignore missing applications
+        exists.append(m)
     if ghosts:
         raise exceptions.GhostMigrations(ghosts)
-
-def currently_applied(histories):
-    applied = []
-    for history in histories:
-        try:
-            applied.append(history.get_migration())
-        except ImproperlyConfigured:
-            pass
-    return applied
+    return exists
 
 def get_dependencies(target, migrations):
     forwards = list
             backwards = migration_before_here.backwards_plan
     return forwards, backwards
 
-def get_direction(target, histories, migrations, verbosity):
+def get_direction(target, applied, migrations, verbosity):
     # Get the forwards and reverse dependencies for this target
     forwards, backwards = get_dependencies(target, migrations)
-    # Get the list of currently applied migrations from the db
-    applied = currently_applied(histories)
     # Is the whole forward branch applied?
     problems = None
     workplan = to_apply(forwards(), applied)
         print "? You have no migrations for the '%s' app. You might want some." % app_name
         return
     # Check there's no strange ones in the database
-    histories = MigrationHistory.objects.filter(applied__isnull=False)
-    check_migration_histories(histories)
+    applied = MigrationHistory.objects.filter(applied__isnull=False)
+    applied = check_migration_histories(applied)
     # Guess the target_name
     target = migrations.guess_migration(target_name)
     if verbosity:
                                                            target.name())
         print "Running migrations for %s:" % app_name
     # Get the forwards and reverse dependencies for this target
-    direction, problems, workplan = get_direction(target, histories,
+    direction, problems, workplan = get_direction(target, applied,
                                                   migrations, verbosity)
     if problems and not (merge or skip):
         raise exceptions.InconsistentMigrationHistory()
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.