feat: restore source parity and harden agent runtime
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
from sqlalchemy import Column, String, Text, Boolean, Integer, JSON, Index
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
|
||||
from app.base_model import BaseModel
|
||||
|
||||
SmartJSON = JSON().with_variant(JSONB(), "postgresql")
|
||||
|
||||
|
||||
class SmartTable(BaseModel):
|
||||
"""多维表格 / 文档"""
|
||||
__tablename__ = "smart_table"
|
||||
|
||||
name = Column(String(200), nullable=False, comment="表名")
|
||||
icon = Column(String(50), default="Grid", comment="图标")
|
||||
description = Column(Text, nullable=True, comment="描述")
|
||||
active_view_id = Column(String(21), nullable=True, comment="当前激活视图ID")
|
||||
type = Column(String(20), default="table", nullable=False, comment="类型: table / document")
|
||||
content = Column(SmartJSON, nullable=True, comment="文档内容(Tiptap JSON), 仅 type=document 时使用")
|
||||
parent_id = Column(String(21), nullable=True, index=True, comment="父页面ID(自引用,用于子页面层级嵌套)")
|
||||
wiki_space_id = Column(String(21), nullable=True, index=True, comment="所属文档库ID")
|
||||
|
||||
|
||||
class SmartField(BaseModel):
|
||||
"""多维表格字段"""
|
||||
__tablename__ = "smart_field"
|
||||
|
||||
table_id = Column(String(21), nullable=False, index=True, comment="所属表ID")
|
||||
name = Column(String(200), nullable=False, comment="字段名")
|
||||
type = Column(String(30), nullable=False, comment="字段类型")
|
||||
width = Column(Integer, default=150, comment="列宽")
|
||||
visible = Column(Boolean, default=True, comment="是否可见")
|
||||
required = Column(Boolean, default=False, comment="是否必填")
|
||||
description = Column(Text, nullable=True, comment="描述")
|
||||
config = Column(SmartJSON, default=dict, comment="扩展配置(options/format/precision等)")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_smart_field_table_sort", "table_id", "sort"),
|
||||
)
|
||||
|
||||
|
||||
class SmartRecord(BaseModel):
|
||||
"""多维表格记录"""
|
||||
__tablename__ = "smart_record"
|
||||
|
||||
table_id = Column(String(21), nullable=False, index=True, comment="所属表ID")
|
||||
values = Column(SmartJSON, default=dict, comment="字段值映射 {fieldId: cellValue}")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_smart_record_table_sort", "table_id", "sort"),
|
||||
)
|
||||
|
||||
|
||||
class SmartTableLink(BaseModel):
|
||||
"""记录关联关系(多对多)"""
|
||||
__tablename__ = "smart_table_link"
|
||||
|
||||
field_id = Column(String(21), nullable=False, index=True, comment="Link字段ID")
|
||||
source_record_id = Column(String(21), nullable=False, index=True, comment="源记录ID")
|
||||
target_record_id = Column(String(21), nullable=False, index=True, comment="目标记录ID")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_link_field_source", "field_id", "source_record_id"),
|
||||
Index("ix_link_field_target", "field_id", "target_record_id"),
|
||||
Index("uq_link_pair", "field_id", "source_record_id", "target_record_id", unique=True),
|
||||
)
|
||||
|
||||
|
||||
class SmartView(BaseModel):
|
||||
"""多维表格视图"""
|
||||
__tablename__ = "smart_view"
|
||||
|
||||
table_id = Column(String(21), nullable=False, index=True, comment="所属表ID")
|
||||
name = Column(String(200), nullable=False, comment="视图名")
|
||||
type = Column(String(30), default="grid", comment="视图类型")
|
||||
config = Column(SmartJSON, default=dict, comment="视图配置(filters/sorts/groups/visibleFieldIds等)")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_smart_view_table_sort", "table_id", "sort"),
|
||||
)
|
||||
|
||||
|
||||
class SmartTableComment(BaseModel):
|
||||
"""记录评论"""
|
||||
__tablename__ = "smart_table_comment"
|
||||
|
||||
record_id = Column(String(21), nullable=False, index=True, comment="所属记录ID")
|
||||
user_id = Column(String(21), nullable=False, index=True, comment="评论者用户ID")
|
||||
content = Column(Text, nullable=False, comment="评论内容(纯文本,含@提及标记)")
|
||||
mentions = Column(SmartJSON, default=list, comment="被@提及的用户ID列表")
|
||||
parent_id = Column(String(21), nullable=True, index=True, comment="父评论ID(用于回复)")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_comment_record_created", "record_id", "sys_create_datetime"),
|
||||
)
|
||||
|
||||
|
||||
class SmartDocumentVersion(BaseModel):
|
||||
"""文档版本历史"""
|
||||
__tablename__ = "smart_document_version"
|
||||
|
||||
document_id = Column(String(21), nullable=False, index=True, comment="文档ID(逻辑外键关联smart_table)")
|
||||
version = Column(Integer, nullable=False, comment="版本号")
|
||||
content = Column(SmartJSON, nullable=False, comment="文档内容快照(Tiptap JSON)")
|
||||
title = Column(String(200), nullable=True, comment="版本标题/文档名称快照")
|
||||
change_summary = Column(String(500), nullable=True, comment="变更摘要")
|
||||
content_size = Column(Integer, default=0, comment="内容大小(字节)")
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_doc_version_doc_ver", "document_id", "version"),
|
||||
Index("ix_doc_version_doc_created", "document_id", "sys_create_datetime"),
|
||||
)
|
||||
|
||||
|
||||
class SmartDocumentTemplate(BaseModel):
|
||||
"""文档模板"""
|
||||
__tablename__ = "smart_document_template"
|
||||
|
||||
name = Column(String(200), nullable=False, comment="模板名称")
|
||||
description = Column(Text, nullable=True, comment="模板描述")
|
||||
icon = Column(String(50), default="FileText", comment="模板图标")
|
||||
category = Column(String(50), default="custom", comment="分类: system / custom")
|
||||
content = Column(SmartJSON, nullable=False, comment="模板内容(Tiptap JSON)")
|
||||
preview_image = Column(String(500), nullable=True, comment="预览图URL")
|
||||
is_system = Column(Boolean, default=False, comment="是否系统预设模板")
|
||||
use_count = Column(Integer, default=0, comment="使用次数")
|
||||
|
||||
|
||||
class SmartWikiSpace(BaseModel):
|
||||
"""文档库/知识空间"""
|
||||
__tablename__ = "smart_wiki_space"
|
||||
|
||||
name = Column(String(200), nullable=False, comment="文档库名称")
|
||||
icon = Column(String(50), default="BookOpen", comment="图标")
|
||||
avatar = Column(String(500), nullable=True, comment="头像文件ID")
|
||||
description = Column(Text, nullable=True, comment="描述")
|
||||
cover = Column(String(500), nullable=True, comment="封面图URL")
|
||||
category = Column(String(50), default="default", comment="分类标签")
|
||||
visibility = Column(String(20), default="private", comment="可见性: private/team/public")
|
||||
Reference in New Issue
Block a user