aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/gmg_commands/dbupdate.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/gmg_commands/dbupdate.py')
-rw-r--r--mediagoblin/gmg_commands/dbupdate.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py
index 27283a20..31827cd0 100644
--- a/mediagoblin/gmg_commands/dbupdate.py
+++ b/mediagoblin/gmg_commands/dbupdate.py
@@ -16,10 +16,11 @@
import logging
+import six
from sqlalchemy.orm import sessionmaker
from mediagoblin.db.open import setup_connection_and_db_from_config
-from mediagoblin.db.migration_tools import MigrationManager
+from mediagoblin.db.migration_tools import MigrationManager, AlembicMigrationManager
from mediagoblin.init import setup_global_and_app_config
from mediagoblin.tools.common import import_component
@@ -106,6 +107,13 @@ forgotten to add it? ({1})'.format(plugin, exc))
return managed_dbdata
+def run_alembic_migrations(db, app_config, global_config):
+ """Initializes a database and runs all Alembic migrations."""
+ Session = sessionmaker(bind=db.engine)
+ manager = AlembicMigrationManager(Session())
+ manager.init_or_migrate()
+
+
def run_dbupdate(app_config, global_config):
"""
Initialize or migrate the database as specified by the config file.
@@ -116,9 +124,14 @@ def run_dbupdate(app_config, global_config):
# Set up the database
db = setup_connection_and_db_from_config(app_config, migrations=True)
- #Run the migrations
+ # Run the migrations
run_all_migrations(db, app_config, global_config)
+ # TODO: Make this happen regardless of python 2 or 3 once ensured
+ # to be "safe"!
+ if six.PY3:
+ run_alembic_migrations(db, app_config, global_config)
+
def run_all_migrations(db, app_config, global_config):
"""
@@ -131,7 +144,7 @@ def run_all_migrations(db, app_config, global_config):
"""
# Gather information from all media managers / projects
dbdatas = gather_database_data(
- global_config.get('plugins', {}).keys())
+ list(global_config.get('plugins', {}).keys()))
Session = sessionmaker(bind=db.engine)