Spaces:
Sleeping
Sleeping
| import os | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import sessionmaker | |
| # Ensure SQLite DB is created in a writable path for Hugging Face Spaces and local | |
| DB_FILENAME = "app.db" | |
| DB_PATH = os.path.join(os.getcwd(), DB_FILENAME) | |
| SQLALCHEMY_DATABASE_URL = f"sqlite:///{DB_PATH}" | |
| # Create the database file if it doesn't exist (touch) | |
| if not os.path.exists(DB_PATH): | |
| open(DB_PATH, "a").close() | |
| engine = create_engine( | |
| SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |