Adds session_mode flag to AC lifecycle. When session_mode=true: - AC transitions to 'active' (not 'consumed') on first CR - Stays active for subsequent CRs during the session - 'session_end' outcome transitions AC to 'consumed' - Non-session ACs behave as before (consumed on first CR) Schema: - ACStatus: add ACTIVE enum value - Outcome: add SESSION_END enum value - AuthorizeRequest: add session_mode bool field - AuthorizationContextDB: add session_mode column - Auto-migration via ALTER TABLE on startup Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
21 lines
786 B
Python
21 lines
786 B
Python
from sqlmodel import SQLModel
|
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncEngine
|
|
from sqlmodel.ext.asyncio.session import AsyncSession
|
|
from gsap_broker.settings import settings
|
|
|
|
engine: AsyncEngine = create_async_engine(settings.database_url, echo=False)
|
|
|
|
async def init_db():
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(SQLModel.metadata.create_all)
|
|
# Schema migrations for existing DBs:
|
|
try:
|
|
await conn.execute(
|
|
__import__("sqlalchemy").text("ALTER TABLE authorization_contexts ADD COLUMN session_mode BOOLEAN DEFAULT 0")
|
|
)
|
|
except Exception:
|
|
pass # Column already exists
|
|
|
|
async def get_session():
|
|
async with AsyncSession(engine) as session:
|
|
yield session
|