from __future__ import annotations from datetime import datetime from decimal import Decimal from sqlalchemy import ( BigInteger, Boolean, Index, Numeric, String, Text, UniqueConstraint, func, ) from sqlalchemy.orm import Mapped, mapped_column from supply_infra.db.base import Base class DemandBelongPoolRel(Base): """需求归属词与需求池行的匹配关系。""" __tablename__ = "demand_belong_pool_rel" __table_args__ = ( UniqueConstraint( "demand_belong_category_id", "multi_demand_pool_di_id", name="uk_belong_pool", ), Index("idx_belong_category_id", "demand_belong_category_id"), Index("idx_pool_di_id", "multi_demand_pool_di_id"), Index("idx_belong_pool_biz_status", "biz_dt", "status"), ) id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True) demand_belong_category_id: Mapped[int] = mapped_column( BigInteger, nullable=False, comment="demand_belong_category.id" ) multi_demand_pool_di_id: Mapped[int] = mapped_column( BigInteger, nullable=False, comment="multi_demand_pool_di.id" ) biz_dt: Mapped[str] = mapped_column( String(32), nullable=False, default="legacy", server_default="legacy", comment="关系证据所属业务日", ) relation_type: Mapped[str] = mapped_column( String(32), nullable=False, default="explicit_token", server_default="explicit_token", comment="关系类型", ) relation_source: Mapped[str] = mapped_column( String(64), nullable=False, default="demand_pool_name_tokens", server_default="legacy", comment="关系来源", ) reason: Mapped[str] = mapped_column( Text, nullable=False, default="上游需求名称中的显式分词命中", comment="建边理由", ) confidence: Mapped[Decimal] = mapped_column( Numeric(6, 5), nullable=False, default=Decimal("1.00000"), server_default="1", ) is_inferred: Mapped[bool] = mapped_column( Boolean, nullable=False, default=True, server_default="1", comment="是否为系统推断关系", ) status: Mapped[str] = mapped_column( String(24), nullable=False, default="active", server_default="active", ) valid_from_biz_dt: Mapped[str] = mapped_column( String(32), nullable=False, default="legacy", server_default="legacy", ) valid_to_biz_dt: Mapped[str | None] = mapped_column(String(32), nullable=True) create_time: Mapped[datetime] = mapped_column( nullable=False, server_default=func.now(), comment="创建时间", ) update_time: Mapped[datetime] = mapped_column( nullable=False, server_default=func.now(), onupdate=func.now(), comment="更新时间", )