from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from pathlib import Path from app.core.config import settings # Create the database directory if it doesn't exist DB_DIR = Path("/app") / "storage" / "db" DB_DIR.mkdir(parents=True, exist_ok=True) SQLALCHEMY_DATABASE_URL = settings.SQLALCHEMY_DATABASE_URI engine = create_engine( SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}, # Needed for SQLite ) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) def get_db(): """ Dependency function that yields db sessions """ db = SessionLocal() try: yield db finally: db.close()