Files
ai-contract-platform/backend/app/models/message.py
T
2026-04-24 13:44:17 +08:00

21 lines
924 B
Python

from datetime import datetime, timezone
from typing import Any, Optional
from sqlalchemy import JSON, DateTime, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from app.db import Base
class Message(Base):
__tablename__ = "messages"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
tenant_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
conversation_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
user_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
role: Mapped[str] = mapped_column(String(20), nullable=False)
content: Mapped[str] = mapped_column(Text, nullable=False)
sources_json: Mapped[Optional[list[dict[str, Any]]]] = mapped_column(JSON, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=lambda: datetime.now(timezone.utc), index=True)