47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import Index, UniqueConstraint
|
|
from sqlmodel import Field, SQLModel
|
|
|
|
|
|
class TopicTopic(SQLModel, table=True):
|
|
__tablename__ = "topic_topic"
|
|
__table_args__ = (
|
|
UniqueConstraint("bot_id", "topic_key", name="uq_topic_topic_bot_topic_key"),
|
|
Index("idx_topic_topic_bot_fallback", "bot_id", "is_default_fallback"),
|
|
)
|
|
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
bot_id: str = Field(foreign_key="bot_instance.id", index=True)
|
|
topic_key: str = Field(index=True)
|
|
name: str = Field(default="")
|
|
description: str = Field(default="")
|
|
is_active: bool = Field(default=True)
|
|
is_default_fallback: bool = Field(default=False)
|
|
routing_json: str = Field(default="{}")
|
|
view_schema_json: str = Field(default="{}")
|
|
created_at: datetime = Field(default_factory=datetime.utcnow, index=True)
|
|
updated_at: datetime = Field(default_factory=datetime.utcnow, index=True)
|
|
|
|
|
|
class TopicItem(SQLModel, table=True):
|
|
__tablename__ = "topic_item"
|
|
__table_args__ = (
|
|
Index("idx_topic_item_bot_topic_created_at", "bot_id", "topic_key", "created_at"),
|
|
Index("idx_topic_item_bot_dedupe", "bot_id", "dedupe_key"),
|
|
)
|
|
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
bot_id: str = Field(foreign_key="bot_instance.id", index=True)
|
|
topic_key: str = Field(index=True)
|
|
title: str = Field(default="")
|
|
content: str = Field(default="")
|
|
level: str = Field(default="info", index=True)
|
|
tags_json: Optional[str] = Field(default=None)
|
|
view_json: Optional[str] = Field(default=None)
|
|
source: str = Field(default="mcp", index=True)
|
|
dedupe_key: Optional[str] = Field(default=None)
|
|
is_read: bool = Field(default=False, index=True)
|
|
created_at: datetime = Field(default_factory=datetime.utcnow, index=True)
|