Override alembic DB URL from DATABASE_URL env var
Fixes migrations inside Docker container where postgres is at postgres:5432, not localhost:5453 as hardcoded in alembic.ini. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8eac800442
commit
0b7964b3dc
1 changed files with 4 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import asyncio
|
||||
import os
|
||||
from logging.config import fileConfig
|
||||
|
||||
from alembic import context
|
||||
|
|
@ -15,6 +16,9 @@ config = context.config
|
|||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
if db_url := os.environ.get("DATABASE_URL"):
|
||||
config.set_main_option("sqlalchemy.url", db_url)
|
||||
|
||||
target_metadata = Base.metadata
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue