You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.5 KiB
Python

from sqlalchemy import ForeignKey, Integer, String, Text, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.core.base_model import ModelMixin, TenantMixin, UserMixin
class RuleModel(ModelMixin, TenantMixin, UserMixin):
"""规则模型"""
__tablename__: str = "rule_list"
__table_args__ = (UniqueConstraint("tenant_id", "name"), {"comment": "规则列表表"})
__loader_options__: list[str] = [
"category",
"created_by",
"updated_by",
"deleted_by",
"tenant_by",
]
name: Mapped[str] = mapped_column(String(128), nullable=False, comment="规则名称", index=True)
category_id: Mapped[int | None] = mapped_column(
Integer,
ForeignKey("rule_category.id", ondelete="SET NULL", onupdate="CASCADE"),
default=None,
nullable=True,
index=True,
comment="规则分类ID",
)
category_name_snapshot: Mapped[str | None] = mapped_column(String(64), default=None, nullable=True, comment="规则分类名称快照")
description: Mapped[str | None] = mapped_column(Text, default=None, nullable=True, comment="规则描述")
prompt_template: Mapped[str] = mapped_column(Text, nullable=False, comment="提示词模板")
status: Mapped[int] = mapped_column(Integer, default=0, nullable=False, comment="状态 0:启用 1:停用", index=True)
category = relationship("RuleCategoryModel", lazy="selectin", foreign_keys=[category_id], uselist=False)