diff --git a/backend-lehrer/vocabulary_db.py b/backend-lehrer/vocabulary_db.py index 4e81a14..0150640 100644 --- a/backend-lehrer/vocabulary_db.py +++ b/backend-lehrer/vocabulary_db.py @@ -15,10 +15,15 @@ from typing import Any, Dict, List, Optional logger = logging.getLogger(__name__) -DATABASE_URL = os.getenv( +_RAW_DB_URL = os.getenv( "DATABASE_URL", "postgresql://breakpilot:breakpilot@postgres:5432/breakpilot", ) +# Strip SQLAlchemy dialect prefix (asyncpg needs plain postgresql://) +DATABASE_URL = _RAW_DB_URL.replace("postgresql+asyncpg://", "postgresql://") +# Strip search_path options (set via SET after connect) +if "options=" in DATABASE_URL: + DATABASE_URL = DATABASE_URL.split("?")[0] if "options=" in DATABASE_URL.split("?")[-1] else DATABASE_URL _pool = None @@ -28,7 +33,10 @@ async def get_pool(): global _pool if _pool is None: import asyncpg - _pool = await asyncpg.create_pool(DATABASE_URL, min_size=2, max_size=10) + _pool = await asyncpg.create_pool( + DATABASE_URL, min_size=2, max_size=10, + server_settings={"search_path": "lehrer,core,public"}, + ) return _pool