This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/runmigration.py

27 lines
828 B
Python
Raw Normal View History

2015-01-23 22:19:15 +00:00
import logging
from alembic.config import Config
from alembic.script import ScriptDirectory
from alembic.environment import EnvironmentContext
from alembic.migration import __name__ as migration_name
2018-06-21 18:48:40 +00:00
def run_alembic_migration(db_uri, log_handler=None, setup_app=True):
2015-01-23 22:19:15 +00:00
if log_handler:
logging.getLogger(migration_name).addHandler(log_handler)
config = Config()
config.set_main_option("script_location", "data:migrations")
config.set_main_option("db_uri", db_uri)
2018-06-21 18:48:40 +00:00
if setup_app:
config.set_main_option('alembic_setup_app', 'True')
else:
config.set_main_option('alembic_setup_app', '')
2015-01-23 22:19:15 +00:00
script = ScriptDirectory.from_config(config)
def fn(rev, context):
return script._upgrade_revs('head', rev)
with EnvironmentContext(config, script, fn=fn, destination_rev='head'):
script.run_env()