AhmadYarAI commited on
Commit
cd8b88c
·
1 Parent(s): 5901fe2

Done the configuration

Browse files
Files changed (1) hide show
  1. core/database.py +8 -3
core/database.py CHANGED
@@ -6,21 +6,26 @@ from dotenv import load_dotenv
6
 
7
  load_dotenv()
8
 
 
9
  DATABASE_URL = os.getenv("DATABASE_URL")
10
 
11
- # HF/Neon can drop idle connections; pre_ping + recycle avoids stale connections.
 
 
 
 
12
  engine = create_engine(
13
  DATABASE_URL,
14
  pool_pre_ping=True,
15
  pool_recycle=300,
16
  )
 
17
  SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
18
  Base = declarative_base()
19
 
20
- # Dependency to get DB session
21
  def get_db():
22
  db = SessionLocal()
23
  try:
24
  yield db
25
  finally:
26
- db.close()
 
6
 
7
  load_dotenv()
8
 
9
+ # 1. Get the URL
10
  DATABASE_URL = os.getenv("DATABASE_URL")
11
 
12
+ # 2. FIX: Convert postgres:// to postgresql:// for SQLAlchemy
13
+ if DATABASE_URL and DATABASE_URL.startswith("postgres://"):
14
+ DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql://", 1)
15
+
16
+ # 3. Create the engine
17
  engine = create_engine(
18
  DATABASE_URL,
19
  pool_pre_ping=True,
20
  pool_recycle=300,
21
  )
22
+
23
  SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
24
  Base = declarative_base()
25
 
 
26
  def get_db():
27
  db = SessionLocal()
28
  try:
29
  yield db
30
  finally:
31
+ db.close()