40 lines
2.1 KiB
Python
40 lines
2.1 KiB
Python
from datetime import datetime
|
|
from sqlalchemy import String, Integer, SmallInteger, Text, ForeignKey, UniqueConstraint, DateTime
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from .base import Base, TimestampMixin, MYSQL_TABLE_ARGS
|
|
|
|
|
|
class PromptTemplate(Base, TimestampMixin):
|
|
__tablename__ = "biz_prompt_template"
|
|
__table_args__ = MYSQL_TABLE_ARGS
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
|
category: Mapped[str] = mapped_column(String(50), nullable=False, default="summary")
|
|
content: Mapped[str] = mapped_column(Text, nullable=False)
|
|
description: Mapped[str | None] = mapped_column(String(255))
|
|
user_id: Mapped[int | None] = mapped_column(Integer, ForeignKey("sys_user.user_id", ondelete="SET NULL"), index=True)
|
|
# Changed Boolean to SmallInteger
|
|
is_system: Mapped[int] = mapped_column(SmallInteger, default=0, nullable=False)
|
|
status: Mapped[int] = mapped_column(Integer, default=1, nullable=False)
|
|
sort_order: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
|
|
|
user_configs = relationship("UserPromptConfig", back_populates="template", cascade="all, delete-orphan")
|
|
|
|
|
|
class UserPromptConfig(Base, TimestampMixin):
|
|
__tablename__ = "biz_user_prompt_config"
|
|
__table_args__ = (
|
|
UniqueConstraint("user_id", "template_id", name="uk_user_template"),
|
|
MYSQL_TABLE_ARGS,
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(Integer, ForeignKey("sys_user.user_id", ondelete="CASCADE"), nullable=False, index=True)
|
|
template_id: Mapped[int] = mapped_column(Integer, ForeignKey("biz_prompt_template.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
# Changed Boolean to SmallInteger
|
|
is_active: Mapped[int] = mapped_column(SmallInteger, default=1, nullable=False)
|
|
user_sort_order: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
|
|
|
template = relationship("PromptTemplate", back_populates="user_configs")
|