global_tree_element.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from __future__ import annotations
  2. from datetime import datetime
  3. from sqlalchemy import BigInteger, Index, Integer, String, UniqueConstraint, func
  4. from sqlalchemy.orm import Mapped, mapped_column
  5. from supply_infra.db.base import Base
  6. class GlobalTreeElement(Base):
  7. """全局树元素 — 从 ODPS pattern_mining_element 同步。"""
  8. __tablename__ = "global_tree_element"
  9. __table_args__ = (
  10. UniqueConstraint("name", "category_id", name="global_tree_element_pk"),
  11. Index("idx_category_id", "category_id"),
  12. )
  13. id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
  14. name: Mapped[str | None] = mapped_column(String(128), nullable=True, comment="名称")
  15. category_id: Mapped[int] = mapped_column(BigInteger, nullable=False, comment="分类id")
  16. source_category_id: Mapped[int] = mapped_column(BigInteger, nullable=False, comment="hive表category_id")
  17. is_delete: Mapped[int] = mapped_column(Integer, default=0, nullable=False, comment="是否删除 0-正常 1-删除")
  18. create_time: Mapped[datetime] = mapped_column(
  19. nullable=False,
  20. server_default=func.now(),
  21. comment="创建时间",
  22. )
  23. update_time: Mapped[datetime] = mapped_column(
  24. nullable=False,
  25. server_default=func.now(),
  26. onupdate=func.now(),
  27. comment="更新时间",
  28. )