Sujith2121's picture
Update app/db/session.py
0bba0d8 verified
raw
history blame contribute delete
623 Bytes
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.core.settings import settings
# Ensure the SQLite directory exists
if settings.DATABASE_URL.startswith("sqlite:///"):
db_path = settings.DATABASE_URL.replace("sqlite:///", "")
db_dir = os.path.dirname(db_path)
if not os.path.exists(db_dir):
os.makedirs(db_dir, exist_ok=True)
# Minimal change to engine
engine = create_engine(
settings.DATABASE_URL,
connect_args={"check_same_thread": False} # only needed for SQLite
)
SessionLocal = sessionmaker(bind=engine, autocommit=False, autoflush=False)