changeset 6020:b9fe529d5752

db: enable Alembic autogeneration of migration scripts
author Søren Løvborg <sorenl@unity3d.com>
date Tue, 05 Jul 2016 16:57:01 +0200
parents ccc66ed2f85b
children c095a2f38add
files kallithea/alembic/env.py
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/alembic/env.py	Mon Jul 18 13:32:34 2016 +0200
+++ b/kallithea/alembic/env.py	Tue Jul 05 16:57:01 2016 +0200
@@ -20,6 +20,8 @@
 from alembic import context
 from sqlalchemy import engine_from_config, pool
 
+from kallithea.model import db
+
 
 # The alembic.config.Config object, which wraps the current .ini file.
 config = context.config
@@ -41,6 +43,16 @@
 fileConfig(config.config_file_name, disable_existing_loggers=False)
 
 
+def include_in_autogeneration(object, name, type, reflected, compare_to):
+    """Filter changes subject to autogeneration of migrations. """
+
+    # Don't include changes to sqlite_sequence.
+    if type == 'table' and name == 'sqlite_sequence':
+        return False
+
+    return True
+
+
 def run_migrations_offline():
     """Run migrations in 'offline' (--sql) mode.
 
@@ -72,6 +84,12 @@
     with connectable.connect() as connection:
         context.configure(
             connection=connection,
+
+            # Support autogeneration of migration scripts based on "diff" between
+            # current database schema and kallithea.model.db schema.
+            target_metadata=db.Base.metadata,
+            include_object=include_in_autogeneration,
+            render_as_batch=True, # batch mode is needed for SQLite support
         )
 
         with context.begin_transaction():