- FastAPI skeleton, SQLAlchemy models (§13), Alembic initial migration - SchedulingProvider interface with google_calendar (free/busy read-only), partner_api (Appendix B client) and mock implementations - Proposal engine: create → provider-routed delivery → owner actions (resolve/confirm+SMS/reject) → expiry + reminders (§9) - Signed single-use action links, .ics METHOD:REQUEST attachment - Partner outcome webhook with HMAC verification + polling fallback - SmsProvider (console) with Bosnian templates (§5.5), EmailProvider (console/SMTP) - Fake partner API server in tests/ — Appendix B reference implementation - 43 tests: slot math, proposal lifecycle, action links, partner contract Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
"""Async SQLAlchemy engine/session setup."""
|
|
|
|
from collections.abc import AsyncIterator
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
|
|
from gogo.config import get_settings
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
_engine = None
|
|
_sessionmaker: async_sessionmaker[AsyncSession] | None = None
|
|
|
|
|
|
def get_engine():
|
|
global _engine, _sessionmaker
|
|
if _engine is None:
|
|
_engine = create_async_engine(get_settings().database_url, pool_pre_ping=True)
|
|
_sessionmaker = async_sessionmaker(_engine, expire_on_commit=False)
|
|
return _engine
|
|
|
|
|
|
def get_sessionmaker() -> async_sessionmaker[AsyncSession]:
|
|
get_engine()
|
|
assert _sessionmaker is not None
|
|
return _sessionmaker
|
|
|
|
|
|
async def get_session() -> AsyncIterator[AsyncSession]:
|
|
"""FastAPI dependency."""
|
|
async with get_sessionmaker()() as session:
|
|
yield session
|
|
|
|
|
|
def reset_engine() -> None:
|
|
"""Test helper: force re-creation of the engine (e.g. after settings change)."""
|
|
global _engine, _sessionmaker
|
|
_engine = None
|
|
_sessionmaker = None
|