mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-27 19:02:31 +08:00
- Replace StaticPool with NullPool in db.py (concurrency write hazard)
- Replace asyncio.get_event_loop() with asyncio.get_running_loop()
in _db_helpers.py (deprecated in Python 3.10+)
- Reorder routes in research_routes.py: specific
/research/assets/{type}/{asset_id} before wildcard {path:.*}
- Add project_id ForeignKey to PaperAsset in models.py
- Add database indexes on frequently queried columns
(library_status, updated_at, project_id, status, source_id)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
28 lines
683 B
Python
28 lines
683 B
Python
"""Research Workbench database session management."""
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
from sqlalchemy.pool import NullPool
|
|
|
|
from research_app.config import get_research_paths
|
|
|
|
_DB_PATH = get_research_paths().db_path
|
|
DATABASE_URL = f"sqlite:///{_DB_PATH}"
|
|
|
|
engine = create_engine(
|
|
DATABASE_URL,
|
|
connect_args={"check_same_thread": False},
|
|
poolclass=NullPool,
|
|
)
|
|
session_maker = sessionmaker(bind=engine)
|
|
|
|
|
|
def create_session():
|
|
"""Create a new database session."""
|
|
return session_maker()
|
|
|
|
|
|
def init_db():
|
|
"""Create all research tables."""
|
|
from research_api.models import Base
|
|
Base.metadata.create_all(engine)
|