forked from hesabix/arc
53 lines
2 KiB
Python
Executable file
53 lines
2 KiB
Python
Executable file
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from sqlalchemy import String, Integer, DateTime, ForeignKey
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from adapters.db.session import Base
|
|
|
|
|
|
class AIChatSession(Base):
|
|
__tablename__ = "ai_chat_sessions"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
|
|
# کاربر و کسبوکار
|
|
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
business_id: Mapped[int | None] = mapped_column(Integer, ForeignKey("businesses.id", ondelete="CASCADE"), nullable=True, index=True)
|
|
|
|
# اطلاعات جلسه
|
|
title: Mapped[str] = mapped_column(String(255), nullable=False, default="جلسه چت جدید")
|
|
execution_mode: Mapped[str] = mapped_column(
|
|
String(32),
|
|
nullable=False,
|
|
default="analyzer",
|
|
server_default="analyzer",
|
|
)
|
|
|
|
# زمانبندی
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
# Relationships
|
|
user = relationship("User", backref="ai_chat_sessions")
|
|
business = relationship("Business", backref="ai_chat_sessions")
|
|
messages = relationship("AIChatMessage", back_populates="session", cascade="all, delete-orphan", order_by="AIChatMessage.created_at")
|
|
attachments = relationship(
|
|
"AIChatAttachment",
|
|
back_populates="session",
|
|
cascade="all, delete-orphan",
|
|
order_by="AIChatAttachment.created_at",
|
|
)
|
|
session_todos = relationship(
|
|
"AISessionTodo",
|
|
back_populates="session",
|
|
cascade="all, delete-orphan",
|
|
order_by="AISessionTodo.sort_order",
|
|
)
|
|
agent_runs = relationship(
|
|
"AIAgentRun",
|
|
back_populates="session",
|
|
cascade="all, delete-orphan",
|
|
order_by="AIAgentRun.created_at",
|
|
)
|
|
|