- Configure Alembic for database migrations with initial schema - Fix base.py to use lazy loading for async engine (avoids import-time issues) - Change AI model from sonnet to haiku (claude-3-haiku-20240307) - Fix pytest version compatibility with pytest-asyncio - Add frontend package-lock.json Phase 1 tasks completed: - F1.1: Development environment (Docker, Node.js 20, Python 3.12, venv) - F1.2: PostgreSQL with 8 categories seeded - F1.3: Redis connection verified - F1.4: Anthropic API configured and tested - F1.5: Backend server + WebSocket verified Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
35 lines
981 B
Python
35 lines
981 B
Python
from sqlalchemy.orm import declarative_base
|
|
|
|
Base = declarative_base()
|
|
|
|
|
|
def get_async_engine():
|
|
"""Create async engine on demand to avoid import-time config issues."""
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
from app.config import get_settings
|
|
|
|
settings = get_settings()
|
|
database_url = settings.database_url.replace(
|
|
"postgresql://", "postgresql+asyncpg://"
|
|
)
|
|
return create_async_engine(database_url, echo=True)
|
|
|
|
|
|
def get_async_session():
|
|
"""Create async session factory."""
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
engine = get_async_engine()
|
|
return sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
|
|
|
|
|
async def get_db():
|
|
"""Dependency for FastAPI routes."""
|
|
AsyncSessionLocal = get_async_session()
|
|
async with AsyncSessionLocal() as session:
|
|
try:
|
|
yield session
|
|
finally:
|
|
await session.close()
|