from pathlib import Path from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker # Define the database directory and ensure it exists DB_DIR = Path("/app/storage/db") DB_DIR.mkdir(parents=True, exist_ok=True) SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_DIR}/db.sqlite" # Create SQLAlchemy engine with SQLite-specific connect_args engine = create_engine( SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} ) # Create a SessionLocal class to get a database session SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)