demand_belong_pool_rel.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. from __future__ import annotations
  2. from datetime import datetime
  3. from decimal import Decimal
  4. from sqlalchemy import (
  5. BigInteger,
  6. Boolean,
  7. Index,
  8. Numeric,
  9. String,
  10. Text,
  11. UniqueConstraint,
  12. func,
  13. )
  14. from sqlalchemy.orm import Mapped, mapped_column
  15. from supply_infra.db.base import Base
  16. class DemandBelongPoolRel(Base):
  17. """需求归属词与需求池行的匹配关系。"""
  18. __tablename__ = "demand_belong_pool_rel"
  19. __table_args__ = (
  20. UniqueConstraint(
  21. "demand_belong_category_id",
  22. "multi_demand_pool_di_id",
  23. name="uk_belong_pool",
  24. ),
  25. Index("idx_belong_category_id", "demand_belong_category_id"),
  26. Index("idx_pool_di_id", "multi_demand_pool_di_id"),
  27. Index("idx_belong_pool_biz_status", "biz_dt", "status"),
  28. )
  29. id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
  30. demand_belong_category_id: Mapped[int] = mapped_column(
  31. BigInteger, nullable=False, comment="demand_belong_category.id"
  32. )
  33. multi_demand_pool_di_id: Mapped[int] = mapped_column(
  34. BigInteger, nullable=False, comment="multi_demand_pool_di.id"
  35. )
  36. biz_dt: Mapped[str] = mapped_column(
  37. String(32),
  38. nullable=False,
  39. default="legacy",
  40. server_default="legacy",
  41. comment="关系证据所属业务日",
  42. )
  43. relation_type: Mapped[str] = mapped_column(
  44. String(32),
  45. nullable=False,
  46. default="explicit_token",
  47. server_default="explicit_token",
  48. comment="关系类型",
  49. )
  50. relation_source: Mapped[str] = mapped_column(
  51. String(64),
  52. nullable=False,
  53. default="demand_pool_name_tokens",
  54. server_default="legacy",
  55. comment="关系来源",
  56. )
  57. reason: Mapped[str] = mapped_column(
  58. Text,
  59. nullable=False,
  60. default="上游需求名称中的显式分词命中",
  61. comment="建边理由",
  62. )
  63. confidence: Mapped[Decimal] = mapped_column(
  64. Numeric(6, 5),
  65. nullable=False,
  66. default=Decimal("1.00000"),
  67. server_default="1",
  68. )
  69. is_inferred: Mapped[bool] = mapped_column(
  70. Boolean,
  71. nullable=False,
  72. default=True,
  73. server_default="1",
  74. comment="是否为系统推断关系",
  75. )
  76. status: Mapped[str] = mapped_column(
  77. String(24),
  78. nullable=False,
  79. default="active",
  80. server_default="active",
  81. )
  82. valid_from_biz_dt: Mapped[str] = mapped_column(
  83. String(32),
  84. nullable=False,
  85. default="legacy",
  86. server_default="legacy",
  87. )
  88. valid_to_biz_dt: Mapped[str | None] = mapped_column(String(32), nullable=True)
  89. create_time: Mapped[datetime] = mapped_column(
  90. nullable=False,
  91. server_default=func.now(),
  92. comment="创建时间",
  93. )
  94. update_time: Mapped[datetime] = mapped_column(
  95. nullable=False,
  96. server_default=func.now(),
  97. onupdate=func.now(),
  98. comment="更新时间",
  99. )