Fix main app migration pathway
This commit is contained in:
parent
561522c6d3
commit
aff1a08a83
4 changed files with 23 additions and 8 deletions
|
@ -19,7 +19,13 @@ from release import GIT_HEAD, REGION, SERVICE
|
|||
from util.morecollections import AttrDict
|
||||
|
||||
config = context.config
|
||||
DB_URI = config.get_main_option('db_uri')
|
||||
DB_URI = config.get_main_option('db_uri', 'sqlite:///test/data/test.db')
|
||||
|
||||
if config.get_main_option('alembic_setup_app', 'True') == 'True':
|
||||
# needed for db connections
|
||||
from app import app
|
||||
DB_URI = app.config['DB_URI']
|
||||
|
||||
config.set_main_option('sqlalchemy.url', unquote(DB_URI))
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
|
@ -68,7 +74,7 @@ def run_migrations_offline():
|
|||
context.configure(url=url, target_metadata=target_metadata, transactional_ddl=True)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations(tables=tables)
|
||||
context.run_migrations(tables=tables, tester=get_tester())
|
||||
|
||||
def run_migrations_online():
|
||||
"""Run migrations in 'online' mode.
|
||||
|
@ -97,7 +103,7 @@ def run_migrations_online():
|
|||
try:
|
||||
with context.begin_transaction():
|
||||
try:
|
||||
context.run_migrations(tables=tables)
|
||||
context.run_migrations(tables=tables, tester=get_tester())
|
||||
except (CommandError, ResolutionError) as ex:
|
||||
if 'No such revision' not in str(ex):
|
||||
raise
|
||||
|
|
|
@ -5,13 +5,19 @@ from alembic.script import ScriptDirectory
|
|||
from alembic.environment import EnvironmentContext
|
||||
from alembic.migration import __name__ as migration_name
|
||||
|
||||
def run_alembic_migration(db_uri, log_handler=None):
|
||||
def run_alembic_migration(db_uri, log_handler=None, setup_app=True):
|
||||
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)
|
||||
|
||||
if setup_app:
|
||||
config.set_main_option('alembic_setup_app', 'True')
|
||||
else:
|
||||
config.set_main_option('alembic_setup_app', '')
|
||||
|
||||
script = ScriptDirectory.from_config(config)
|
||||
|
||||
def fn(rev, context):
|
||||
|
|
Reference in a new issue