34 lines
1.5 KiB
Python
34 lines
1.5 KiB
Python
"""飞书/消息对话会话状态。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import BigInteger, ForeignKey, Index, Integer, TIMESTAMP, UniqueConstraint, VARCHAR, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from .base import BaseNoTenant
|
|
|
|
|
|
class ConversationSession(BaseNoTenant):
|
|
__tablename__ = "conversation_sessions"
|
|
__table_args__ = (
|
|
UniqueConstraint("tenant_id", "sender", name="uq_conversation_sessions_tenant_sender"),
|
|
Index("ix_conversation_sessions_tenant_sender_last_active", "tenant_id", "sender", "last_active_at"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
tenant_id: Mapped[int] = mapped_column(BigInteger, nullable=False, default=1, index=True)
|
|
sender: Mapped[str] = mapped_column(VARCHAR(128), nullable=False, index=True)
|
|
current_project_id: Mapped[Optional[int]] = mapped_column(
|
|
BigInteger,
|
|
ForeignKey("projects.id"),
|
|
nullable=True,
|
|
index=True,
|
|
)
|
|
last_intent: Mapped[Optional[str]] = mapped_column(VARCHAR(64), nullable=True, index=True)
|
|
last_message_text: Mapped[Optional[str]] = mapped_column(VARCHAR(200), nullable=True)
|
|
last_active_at: Mapped[datetime] = mapped_column(TIMESTAMP, nullable=False, default=func.now(), index=True)
|
|
created_at: Mapped[datetime] = mapped_column(TIMESTAMP, nullable=False, default=func.now(), server_default=func.now())
|