fix: env.py reads FABLEDNETMON_DATABASE_URL and honors URL set by migration_runner
This commit is contained in:
@@ -23,12 +23,21 @@ def get_url() -> str:
|
|||||||
url = cfg.get("database", {}).get("url", "")
|
url = cfg.get("database", {}).get("url", "")
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
url = ""
|
url = ""
|
||||||
return os.environ.get("FABLEDNETMON_DATABASE__URL", url)
|
return (
|
||||||
|
os.environ.get("FABLEDNETMON_DATABASE_URL")
|
||||||
|
or os.environ.get("FABLEDNETMON_DATABASE__URL")
|
||||||
|
or url
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _resolved_url() -> str:
|
||||||
|
"""Return URL from migration_runner config if set, else fall back to get_url()."""
|
||||||
|
return config.get_main_option("sqlalchemy.url") or get_url()
|
||||||
|
|
||||||
|
|
||||||
def run_migrations_offline() -> None:
|
def run_migrations_offline() -> None:
|
||||||
context.configure(
|
context.configure(
|
||||||
url=get_url(), target_metadata=target_metadata,
|
url=_resolved_url(), target_metadata=target_metadata,
|
||||||
literal_binds=True, dialect_opts={"paramstyle": "named"},
|
literal_binds=True, dialect_opts={"paramstyle": "named"},
|
||||||
)
|
)
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
@@ -43,7 +52,7 @@ def do_run_migrations(connection: Connection) -> None:
|
|||||||
|
|
||||||
async def run_async_migrations() -> None:
|
async def run_async_migrations() -> None:
|
||||||
cfg = config.get_section(config.config_ini_section, {})
|
cfg = config.get_section(config.config_ini_section, {})
|
||||||
cfg["sqlalchemy.url"] = get_url()
|
cfg["sqlalchemy.url"] = _resolved_url()
|
||||||
connectable = async_engine_from_config(cfg, prefix="sqlalchemy.", poolclass=pool.NullPool)
|
connectable = async_engine_from_config(cfg, prefix="sqlalchemy.", poolclass=pool.NullPool)
|
||||||
async with connectable.connect() as connection:
|
async with connectable.connect() as connection:
|
||||||
await connection.run_sync(do_run_migrations)
|
await connection.run_sync(do_run_migrations)
|
||||||
|
|||||||
Reference in New Issue
Block a user