fix(infrastructure): alembic - use SSL for DB connection

This commit is contained in:
2025-10-02 15:10:09 +02:00
parent 42f3d4dae1
commit dd0ca4b4f1

View File

@@ -23,9 +23,10 @@ if not DATABASE_URL:
mariadb_password = os.getenv("MARIADB_PASSWORD", "strongpassword")
DATABASE_URL = f"mysql+pymysql://{mariadb_user}:{mariadb_password}@{mariadb_host}:{mariadb_port}/{mariadb_db}"
# Use synchronous driver for Alembic migrations
SYNC_DATABASE_URL = DATABASE_URL.replace("+asyncmy", "+pymysql")
ssl_enabled = os.getenv("MARIADB_HOST", "localhost") != "localhost"
connect_args = {"ssl": {"ssl": True}} if ssl_enabled else {}
def run_migrations_offline() -> None:
context.configure(
@@ -39,7 +40,7 @@ def run_migrations_offline() -> None:
def run_migrations_online() -> None:
connectable = create_engine(SYNC_DATABASE_URL, poolclass=pool.NullPool)
connectable = create_engine(SYNC_DATABASE_URL, poolclass=pool.NullPool, connect_args=connect_args)
with connectable.connect() as connection:
context.configure(
connection=connection,