global_tree_category.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from __future__ import annotations
  2. from datetime import datetime
  3. from sqlalchemy import BigInteger, Integer, String, Text, UniqueConstraint, func
  4. from sqlalchemy.orm import Mapped, mapped_column
  5. from supply_infra.db.base import Base
  6. class GlobalTreeCategory(Base):
  7. """全局树分类 — 从 ODPS global_category 同步。"""
  8. __tablename__ = "global_tree_category"
  9. __table_args__ = (UniqueConstraint("source_id", name="uk_source_id"),)
  10. id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
  11. name: Mapped[str | None] = mapped_column(String(128), nullable=True, comment="名称")
  12. description: Mapped[str | None] = mapped_column(Text, nullable=True, comment="描述")
  13. level: Mapped[int | None] = mapped_column(Integer, nullable=True, comment="层级")
  14. parent_id: Mapped[int | None] = mapped_column(BigInteger, nullable=True, comment="父节点")
  15. source_id: Mapped[int] = mapped_column(
  16. BigInteger,
  17. nullable=False,
  18. comment="global_category.stable_id",
  19. )
  20. source_parent_id: Mapped[int] = mapped_column(
  21. BigInteger,
  22. nullable=False,
  23. comment="global_category.parent_stable_id",
  24. )
  25. is_delete: Mapped[int] = mapped_column(Integer, default=0, nullable=False, comment="是否删除0-正常 1-删除")
  26. create_time: Mapped[datetime | None] = mapped_column(
  27. nullable=True,
  28. server_default=func.now(),
  29. comment="创建时间",
  30. )
  31. update_time: Mapped[datetime] = mapped_column(
  32. nullable=False,
  33. server_default=func.now(),
  34. onupdate=func.now(),
  35. comment="更新时间",
  36. )