Spaces:
Running
Running
Anish-530 commited on
Commit ·
96c41f2
1
Parent(s): 9e1fb8a
Fix database URL driver normalization for psycopg2
Browse files- backend/app/db/database.py +10 -1
backend/app/db/database.py
CHANGED
|
@@ -7,8 +7,17 @@ if settings.DATABASE_URL.startswith("sqlite"):
|
|
| 7 |
connect_args={"check_same_thread": False}
|
| 8 |
)
|
| 9 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
engine = create_engine(
|
| 11 |
-
|
| 12 |
pool_pre_ping=True,
|
| 13 |
pool_recycle=300,
|
| 14 |
pool_size=10,
|
|
|
|
| 7 |
connect_args={"check_same_thread": False}
|
| 8 |
)
|
| 9 |
else:
|
| 10 |
+
db_url = settings.DATABASE_URL
|
| 11 |
+
# Normalize PaaS postgres:// or postgresql:// URLs to explicitly use the psycopg2 driver
|
| 12 |
+
if db_url.startswith("postgres://"):
|
| 13 |
+
db_url = db_url.replace("postgres://", "postgresql+psycopg2://", 1)
|
| 14 |
+
elif db_url.startswith("postgresql://"):
|
| 15 |
+
db_url = db_url.replace("postgresql://", "postgresql+psycopg2://", 1)
|
| 16 |
+
elif db_url.startswith("postgresql+psycopg://"):
|
| 17 |
+
db_url = db_url.replace("postgresql+psycopg://", "postgresql+psycopg2://", 1)
|
| 18 |
+
|
| 19 |
engine = create_engine(
|
| 20 |
+
db_url,
|
| 21 |
pool_pre_ping=True,
|
| 22 |
pool_recycle=300,
|
| 23 |
pool_size=10,
|