1. Ronny Pfannschmidt
  2. micromigrate

Commits

Ronny Pfannschmidt  committed b9dbdd8

refactor everything

  • Participants
  • Parent commits 2a76b46
  • Branches default

Comments (0)

Files changed (5)

File micromigrate/__init__.py

View file
 __all__ = [
+    'MigrationError',
     'apply_migrations', 'parse_migration',
     'find_in_path',
 ]
+from .types import MigrationError
 from .util import apply_migrations, parse_migration
 from .finder import find_in_path

File micromigrate/backend_script.py

View file
         try:
             self.run_query(script)
         except Exception as e:
-            raise MigrationError('migration failed', e)
+            raise MigrationError(migration, e)
 
     def run_query(self, query):
         out = output_or_raise(

File micromigrate/types.py

View file
 
 class MigrationError(Exception):
     def __str__(self):
-        return "%s %s" % (
-            self.args[0],
+        return "migration `%s` failed: %s" % (
+            self.args[0].name,
             self.args[-1].args[-1]['err'])

File micromigrate/util.py

View file
 
     print(missing_migrations)
     while missing_migrations:
-        migration = pop_next_to_apply(missing_migrations, state)
-        try:
-            db.apply(migration)
-        except Exception as e:
-            print(migration, 'failed', e)
-            break
+        migration = pop_next_to_apply(
+                missing_migrations, state)
+        db.apply(migration)
         state[migration.name] = migration.checksum
     real_state = db.state()
     if real_state is not None:

File testing/test_miromigrate.py

View file
 import pytest
 from micromigrate import parse_migration, apply_migrations
 from micromigrate.backend_script import ScriptBackend
+from micromigrate import MigrationError
 
 
 @pytest.fixture
         insert into foo values ('a');
         insert into foo values ('a');
         """)
-    state = apply_migrations(db, [migration])
-    assert state is None
+    with pytest.raises(MigrationError):
+        apply_migrations(db, [migration])