Commits

Ronny Pfannschmidt committed 29b45d8

fixes and kill implicit migrations

Comments (0)

Files changed (3)

filetrack/__init__.py

-import py
-import sqlite3
-from functools import wraps
-from contextlib import closing
-
 __all__ = [
     'load',
     'repos',

filetrack/analyze.py

-from . import appcommand
+from .utils import appcommand
 
 
 REPOS = '''

filetrack/utils.py

-from micromigrate import find_in_path, apply_migrations
+import py
+import sqlite3
+from contextlib import closing
+from functools import wraps
+
+from micromigrate import find_in_path, apply_migrations, missing_migrations
 from micromigrate.backend_script import ScriptBackend
 
 
+def needs_migrate(dbname):
+    return _micromigrate(dbname, missing_migrations)
+
 def do_migrate(dbname):
+    _micromigrate(sbname, apply_migrations)
+
+def _micromigrate(dbname, command):
     here = py.path.local(__file__).dirpath().join('migrations')
     migrations = list(find_in_path(here))
     migrator = ScriptBackend(dbname)
-    apply_migrations(migrator, migrations)
+    return command(migrator, migrations)
 
 
 def appcommand(func):
     @wraps(func)
     def command(dbname, *args):
-        do_migrate(dbname)
+        missing = needs_migrate(dbname)
+        if missing:
+            print 'missing migrations', sorted(missing)
+            raise SystemExit(1)
         db = sqlite3.connect(dbname)
         with closing(db):
             func(db, *args)