forked from platypush/platypush
Pass the configuration file used by the application to the Alembic process.
The database settings could also be overridden in the configuration file besides the command line. We should therefore pass the path to the runtime configuration file, so the Alembic process can initialize its configuration from the same file and use the same settings.
This commit is contained in:
parent
1825b492b3
commit
a8255f3621
3 changed files with 14 additions and 0 deletions
|
@ -530,5 +530,12 @@ class Config:
|
|||
# pylint: disable=protected-access
|
||||
cls._get_instance()._config[key] = value
|
||||
|
||||
@classmethod
|
||||
def get_file(cls) -> str:
|
||||
"""
|
||||
:return: The main configuration file path.
|
||||
"""
|
||||
return cls._get_instance().config_file
|
||||
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
|
|
@ -29,6 +29,7 @@ from sqlalchemy.orm import ColumnProperty, backref, relationship
|
|||
from sqlalchemy.orm.exc import ObjectDeletedError
|
||||
|
||||
import platypush
|
||||
from platypush.config import Config
|
||||
from platypush.common.db import Base
|
||||
from platypush.message import JSONAble, Message
|
||||
|
||||
|
@ -355,6 +356,8 @@ def run_db_migrations():
|
|||
'-c',
|
||||
alembic_ini,
|
||||
'-x',
|
||||
f'CFGFILE={Config.get_file()}',
|
||||
'-x',
|
||||
f'DBNAME={_get_db_engine().url}',
|
||||
'upgrade',
|
||||
'head',
|
||||
|
|
|
@ -74,6 +74,10 @@ def run_migrations_online() -> None:
|
|||
|
||||
|
||||
def set_db_engine():
|
||||
app_conf_file = context.get_x_argument(as_dictionary=True).get('CFGFILE')
|
||||
if app_conf_file:
|
||||
Config.init(app_conf_file)
|
||||
|
||||
engine_url = context.get_x_argument(as_dictionary=True).get('DBNAME')
|
||||
if not engine_url:
|
||||
db_conf = Config.get('db')
|
||||
|
|
Loading…
Reference in a new issue