fix(alembic): URL-decode DATABASE_URL before passing to ConfigParser
Some checks failed
CI / Detect changes (push) Has been cancelled
CI / API Lint (push) Has been cancelled
CI / Admin UI Tests (push) Has been cancelled
CI / Admin UI Build (push) Has been cancelled
CI / API Tests (push) Has been cancelled
CI / Scanner Lint (push) Has been cancelled
CI / Scanner Tests (push) Has been cancelled
CI / Banner Lint & Typecheck (push) Has been cancelled
CI / Banner Tests (push) Has been cancelled
CI / Banner Build (push) Has been cancelled
CI / Admin UI Typecheck (push) Has been cancelled

This commit is contained in:
Ami
2026-04-21 17:43:17 +07:00
parent 6a513a97ce
commit 283f75a5e2

View File

@@ -1,5 +1,6 @@
import os import os
from logging.config import fileConfig from logging.config import fileConfig
from urllib.parse import unquote
from sqlalchemy import engine_from_config, pool from sqlalchemy import engine_from_config, pool
@@ -14,6 +15,9 @@ database_url = os.environ.get("DATABASE_URL")
if database_url: if database_url:
# Alembic needs the synchronous driver # Alembic needs the synchronous driver
database_url = database_url.replace("postgresql+asyncpg://", "postgresql://") database_url = database_url.replace("postgresql+asyncpg://", "postgresql://")
# Decode URL-encoded characters (e.g. %40 -> @) so ConfigParser
# interpolation doesn't choke on them
database_url = unquote(database_url)
config.set_main_option("sqlalchemy.url", database_url) config.set_main_option("sqlalchemy.url", database_url)
# Set up Python logging from the config file # Set up Python logging from the config file