from __future__ import annotations from sqlalchemy import Boolean, Index, Integer, String from sqlalchemy.orm import Mapped, mapped_column from app.models.base import Base, SoftDeleteMixin, TimestampMixin class HomeMaterialCategory(Base, TimestampMixin, SoftDeleteMixin): """首页素材行业类别。""" __tablename__ = "home_material_categories" __table_args__ = ( Index("idx_home_material_categories_active_sort", "deleted_at", "is_active", "sort_order", "created_at"), Index("idx_home_material_categories_key", "key"), ) id: Mapped[str] = mapped_column(String(32), primary_key=True) name: Mapped[str] = mapped_column(String(64), nullable=False, index=True, comment="行业名称") key: Mapped[str] = mapped_column(String(64), nullable=False, comment="行业唯一标识,前台可按 key 查询") description: Mapped[str | None] = mapped_column(String(255), nullable=True, comment="行业描述") icon: Mapped[str | None] = mapped_column(String(64), nullable=True, comment="前端图标名称") is_active: Mapped[bool] = mapped_column( Boolean, default=True, server_default="true", nullable=False, index=True, comment="是否启用", ) sort_order: Mapped[int] = mapped_column( Integer, default=0, server_default="0", nullable=False, index=True, comment="排序,越小越靠前", ) created_by: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True, comment="创建管理员ID") updated_by: Mapped[str | None] = mapped_column(String(32), nullable=True, index=True, comment="更新管理员ID")