Simon Law avatar Simon Law committed 3ae596e

Simplify migrate_app()'s parameters

Comments (0)

Files changed (3)

south/exceptions.py

                 "    %s") % trace
 
 
+class InconsistentMigrationHistory(SouthError):
+    def __str__(self):
+        return ('Inconsistent migration history\n'
+                'The following options are available:\n'
+                '    --merge: will just attempt the migration ignoring any potential dependency conflicts.')
+
+
 class DependsOnHigherMigration(SouthError):
     def __init__(self, migration, depends_on):
         self.migration = migration

south/migration/__init__.py

         migrator = LoadInitialDataMigrator(migrator=migrator)
     return migrator
 
-def migrate_app(migrations, target_name=None, resolve_mode=None, fake=False, db_dry_run=False, yes=False, verbosity=0, load_initial_data=False, skip=False):
+def migrate_app(migrations, target_name=None, merge=False, fake=False, db_dry_run=False, yes=False, verbosity=0, load_initial_data=False, skip=False):
     
     app_name = migrations.app_name()
     app = migrations._migrations
     # Get the forwards and reverse dependencies for this target
     direction, problems, workplan = get_direction(target, histories,
                                                   migrations, verbosity)
-    if problems and resolve_mode not in ['merge'] and not skip:
-        print " ! Inconsistent migration history"
-        print " ! The following options are available:"
-        print "    --merge: will just attempt the migration ignoring any potential dependency conflicts."
-        sys.exit(1)
+    if problems and not merge and not skip:
+        raise exceptions.InconsistentMigrationHistory()
     # Perform the migration
     migrator = get_migrator(direction,
                             db_dry_run, fake, verbosity, load_initial_data)

south/tests/logic.py

         self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
         
         # Apply them normally
-        migration.migrate_app(migrations, target_name=None, resolve_mode=None, fake=False, verbosity=0, load_initial_data=True)
+        migration.migrate_app(migrations, target_name=None, fake=False,
+                              load_initial_data=True)
         
         # We should finish with all migrations
         self.assertListEqual(
         )
         
         # Now roll them backwards
-        migration.migrate_app(migrations, target_name="zero", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(migrations, target_name="zero", fake=False)
         
         # Finish with none
         self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
             migration.MigrationHistory.objects.values_list("app_name", "migration"),
         )
         
-        # Apply them normally
+        # Redirect the error it will print to nowhere
+        stdout, sys.stdout = sys.stdout, StringIO.StringIO()
         try:
-            # Redirect the error it will print to nowhere
-            stdout, sys.stdout = sys.stdout, StringIO.StringIO()
-            migration.migrate_app(migrations, target_name=None, resolve_mode=None, fake=False, verbosity=0)
+            # Apply them normally
+            self.assertRaises(exceptions.InconsistentMigrationHistory,
+                              migration.migrate_app,
+                              migrations, target_name=None, fake=False)
+        finally:
             sys.stdout = stdout
-        except SystemExit:
-            pass
         
         # Nothing should have changed (no merge mode!)
         self.assertListEqual(
             migration.MigrationHistory.objects.values_list("app_name", "migration"),
         )
         
-        # Apply with merge
-        migration.migrate_app(migrations, target_name=None, resolve_mode="merge", fake=False, verbosity=0)
+        # Redirect the error it will print to nowhere
+        stdout, sys.stdout = sys.stdout, StringIO.StringIO()
+        try:
+            # Apply with merge
+            migration.migrate_app(migrations, target_name=None,
+                                  merge=True, fake=False)
+        finally:
+            sys.stdout = stdout
         
         # We should finish with all migrations
         self.assertListEqual(
         )
         
         # Now roll them backwards
-        migration.migrate_app(migrations, target_name="0002", resolve_mode=None, fake=False, verbosity=0)
-        migration.migrate_app(migrations, target_name="0001", resolve_mode=None, fake=True, verbosity=0)
-        migration.migrate_app(migrations, target_name="zero", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(migrations, target_name="0002", fake=False)
+        migration.migrate_app(migrations, target_name="0001", fake=True)
+        migration.migrate_app(migrations, target_name="zero", fake=False)
         
         # Finish with none
         self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
         self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
         
         # by default name is NOT NULL
-        migration.migrate_app(migrations, target_name="0002", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(migrations, target_name="0002", fake=False)
         self.failIf(null_ok())
         
         # after 0003, it should be NULL
-        migration.migrate_app(migrations, target_name="0003", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(migrations, target_name="0003", fake=False)
         self.assert_(null_ok())
 
         # make sure it is NOT NULL again
-        migration.migrate_app(migrations, target_name="0002", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(migrations, target_name="0002", fake=False)
         self.failIf(null_ok(), 'name not null after migration')
         
         # finish with no migrations, otherwise other tests fail...
-        migration.migrate_app(migrations, target_name="zero", resolve_mode=None, fake=False, verbosity=0)
+        migration.migrate_app(migrations, target_name="zero", fake=False)
         self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
     
     def test_dependencies(self):
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.