Spaces:
Build error
Build error
| from sqlalchemy import create_engine | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import sessionmaker | |
| from app.config import settings | |
| import os | |
| import platform | |
| BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| # Use /tmp on Linux (HF Spaces) to ensure write permissions | |
| if platform.system() == "Linux": | |
| db_path = "/tmp/andesops.db" | |
| else: | |
| db_path = os.path.join(BASE_DIR, "andesops.db") | |
| default_db_path = f"sqlite:///{db_path}" | |
| SQLALCHEMY_DATABASE_URL = settings.database_url or default_db_path | |
| # SQLite specific config for FastAPI multi-threading | |
| connect_args = {"check_same_thread": False} if SQLALCHEMY_DATABASE_URL.startswith("sqlite") else {} | |
| engine = create_engine( | |
| SQLALCHEMY_DATABASE_URL, connect_args=connect_args | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |