from datetime import datetime from sqlalchemy.orm import Mapped, mapped_column from sqlalchemy import String, Text, Integer, DateTime, Index, func from models.base import Base class Script(Base): __tablename__ = "t_script" id: Mapped[int] = mapped_column( Integer, primary_key=True, autoincrement=True, comment="自动递增的唯一内容ID" ) project: Mapped[str] = mapped_column( String(64), nullable=False, index=True, comment="项目名称" ) subject: Mapped[str] = mapped_column( String(256), nullable=False, comment="主题" ) content: Mapped[str | None] = mapped_column( Text, nullable=True, comment="内容" ) create_time: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now(), nullable=False, comment="创建时间" ) update_time: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False, comment="更新时间" ) # ——可选优化:添加 项目 + 主题 联合唯一索引—— __table_args__ = ( Index("ux_project_subject", "project", "subject", unique=True), ) def __repr__(self): return f"