Fix alembic migrations importing app
Ensure we connect to loaded config db
This commit is contained in:
parent
bb2b28cd11
commit
b5f630ba29
18 changed files with 69 additions and 81 deletions
|
@ -14,14 +14,13 @@ from peewee import SqliteDatabase
|
|||
from data.database import all_models, db
|
||||
from data.migrations.tester import NoopTester, PopulateTestDataTester
|
||||
|
||||
from app import app
|
||||
from data.model.sqlalchemybridge import gen_sqlalchemy_metadata
|
||||
from release import GIT_HEAD, REGION, SERVICE
|
||||
from util.morecollections import AttrDict
|
||||
|
||||
config = context.config
|
||||
config.set_main_option('sqlalchemy.url', unquote(app.config['DB_URI']))
|
||||
|
||||
DB_URI = config.get_main_option('db_uri')
|
||||
config.set_main_option('sqlalchemy.url', unquote(DB_URI))
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
if config.config_file_name:
|
||||
|
@ -47,7 +46,7 @@ def get_tester():
|
|||
connecting to a production database.
|
||||
"""
|
||||
if os.environ.get('TEST_MIGRATE', '') == 'true':
|
||||
url = unquote(app.config['DB_URI'])
|
||||
url = unquote(DB_URI)
|
||||
if url.find('.quay.io') < 0:
|
||||
return PopulateTestDataTester()
|
||||
|
||||
|
@ -65,12 +64,11 @@ def run_migrations_offline():
|
|||
script output.
|
||||
|
||||
"""
|
||||
url = unquote(app.config['DB_URI'])
|
||||
url = unquote(DB_URI)
|
||||
context.configure(url=url, target_metadata=target_metadata, transactional_ddl=True)
|
||||
|
||||
with context.begin_transaction():
|
||||
context.run_migrations(tables=tables, tester=get_tester())
|
||||
|
||||
context.run_migrations(tables=tables)
|
||||
|
||||
def run_migrations_online():
|
||||
"""Run migrations in 'online' mode.
|
||||
|
@ -99,7 +97,7 @@ def run_migrations_online():
|
|||
try:
|
||||
with context.begin_transaction():
|
||||
try:
|
||||
context.run_migrations(tables=tables, tester=get_tester())
|
||||
context.run_migrations(tables=tables)
|
||||
except (CommandError, ResolutionError) as ex:
|
||||
if 'No such revision' not in str(ex):
|
||||
raise
|
||||
|
|
Reference in a new issue