forked from hesabix/arc
42 lines
1.7 KiB
Python
42 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from adapters.db.session import Base
|
|
|
|
|
|
class AIMemoryItem(Base):
|
|
"""آیتم حافظهٔ بلندمدت — CRUD دقیق توسط دستیار."""
|
|
|
|
__tablename__ = "ai_memory_items"
|
|
__table_args__ = (
|
|
UniqueConstraint(
|
|
"business_id",
|
|
"user_id",
|
|
"item_key",
|
|
name="uq_ai_memory_item_business_user_key",
|
|
),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
business_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("businesses.id", ondelete="CASCADE"), nullable=False, index=True
|
|
)
|
|
user_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True
|
|
)
|
|
item_key: Mapped[str] = mapped_column(String(128), nullable=False)
|
|
category: Mapped[str] = mapped_column(String(32), nullable=False, default="fact")
|
|
content: Mapped[str] = mapped_column(Text, nullable=False, default="")
|
|
structured: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
source: Mapped[str] = mapped_column(String(32), nullable=False, default="assistant")
|
|
confidence: Mapped[Optional[str]] = mapped_column(String(16), nullable=True)
|
|
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
|
|
)
|
|
deleted_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|