| 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) | |