Monteeq CI commited on
Commit
154f032
·
1 Parent(s): 8ad8368

🚀 Deploy from GitHub @ 4d3814559c615ee44b541e9d429783c55d4bbc5c

Browse files

Triggered by: Smasduq
Message: fix: force psycopg2 driver for Postgres URLs to avoid missing psycopg

Files changed (2) hide show
  1. app/core/config.py +5 -0
  2. app/db/session.py +6 -0
app/core/config.py CHANGED
@@ -36,6 +36,11 @@ CORS_ALLOW_ORIGIN_REGEX = os.getenv(
36
 
37
  # Database Configuration
38
  DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./sql_app.db")
 
 
 
 
 
39
 
40
  # Quota Limits
41
  FLASH_QUOTA_LIMIT = 50
 
36
 
37
  # Database Configuration
38
  DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./sql_app.db")
39
+ # Normalize Postgres URLs to use psycopg2 if no driver specified (psycopg3 may not be installed)
40
+ if DATABASE_URL and DATABASE_URL.startswith("postgresql://"):
41
+ DATABASE_URL = DATABASE_URL.replace("postgresql://", "postgresql+psycopg2://", 1)
42
+ elif DATABASE_URL and DATABASE_URL.startswith("postgres://"):
43
+ DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql+psycopg2://", 1)
44
 
45
  # Quota Limits
46
  FLASH_QUOTA_LIMIT = 50
app/db/session.py CHANGED
@@ -4,6 +4,12 @@ from app.core.config import DATABASE_URL
4
 
5
  SQLALCHEMY_DATABASE_URL = DATABASE_URL
6
 
 
 
 
 
 
 
7
  # Remove check_same_thread for postgres
8
  if SQLALCHEMY_DATABASE_URL and SQLALCHEMY_DATABASE_URL.startswith("sqlite"):
9
  engine = create_engine(
 
4
 
5
  SQLALCHEMY_DATABASE_URL = DATABASE_URL
6
 
7
+ # Ensure we use psycopg2 if driver not specified (psycopg v3 may not be installed)
8
+ if SQLALCHEMY_DATABASE_URL and SQLALCHEMY_DATABASE_URL.startswith("postgresql://"):
9
+ SQLALCHEMY_DATABASE_URL = SQLALCHEMY_DATABASE_URL.replace("postgresql://", "postgresql+psycopg2://", 1)
10
+ elif SQLALCHEMY_DATABASE_URL and SQLALCHEMY_DATABASE_URL.startswith("postgres://"):
11
+ SQLALCHEMY_DATABASE_URL = SQLALCHEMY_DATABASE_URL.replace("postgres://", "postgresql+psycopg2://", 1)
12
+
13
  # Remove check_same_thread for postgres
14
  if SQLALCHEMY_DATABASE_URL and SQLALCHEMY_DATABASE_URL.startswith("sqlite"):
15
  engine = create_engine(