Spaces:
Sleeping
Sleeping
fix: fix cloud db connection fail
Browse files- backend/app/core/db.py +11 -1
backend/app/core/db.py
CHANGED
|
@@ -6,8 +6,18 @@ from sqlmodel.ext.asyncio.session import AsyncSession
|
|
| 6 |
|
| 7 |
from backend.app.core.config import settings
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
async_engine: AsyncEngine = create_async_engine(
|
| 10 |
-
|
| 11 |
)
|
| 12 |
|
| 13 |
async_session_factory = async_sessionmaker(
|
|
|
|
| 6 |
|
| 7 |
from backend.app.core.config import settings
|
| 8 |
|
| 9 |
+
db_url = settings.DATABASE_URL
|
| 10 |
+
connect_args = {}
|
| 11 |
+
|
| 12 |
+
if "sslmode=" in db_url:
|
| 13 |
+
db_url = db_url.replace("?sslmode=require", "").replace("&sslmode=require", "")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
if "neon.tech" in db_url:
|
| 17 |
+
connect_args = {"ssl": "require"}
|
| 18 |
+
|
| 19 |
async_engine: AsyncEngine = create_async_engine(
|
| 20 |
+
db_url, echo=False, future=True, connect_args=connect_args
|
| 21 |
)
|
| 22 |
|
| 23 |
async_session_factory = async_sessionmaker(
|