Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python
978 B
Raw Blame
"""Session ownership — replaces ``data/session_ownership.json``.

Maps a chat session_id (== response_id) to the owning user. Used for
access-control checks: only the owning user can read/release a session.

The user_id column is intentionally NOT a foreign key — legacy JSON
state may reference user_ids that haven't been backfilled into the
``users`` table yet, and we don't want migration to fail on FK
violations.
"""

from datetime import UTC, datetime

from sqlmodel import Field, SQLModel


class SessionOwnership(SQLModel, table=True):
    __tablename__ = "session_ownership"

    response_id: str = Field(primary_key=True, max_length=64)
    user_id: str = Field(max_length=64, index=True)
    # Null legacy rows are their own canonical conversation.
    conversation_id: str | None = Field(default=None, max_length=64, index=True)
    created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
    last_accessed: datetime | None = Field(default=None)