import os from pathlib import Path from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker # Use current working directory if /app doesn't exist base_path = Path("/app") if Path("/app").exists() else Path.cwd() DB_DIR = base_path / "storage" / "db" DB_DIR.mkdir(parents=True, exist_ok=True) SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite" engine = create_engine( SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} ) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) def get_db(): db = SessionLocal() try: yield db finally: db.close()