category.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. """方案分类模型。"""
  2. from __future__ import annotations
  3. from sqlalchemy import BigInteger, CheckConstraint, ForeignKey, Index, Integer, String, text
  4. from sqlalchemy.orm import Mapped, mapped_column
  5. from dms.database.base import BusinessTableMixin
  6. from dms.extensions import db
  7. class Category(BusinessTableMixin, db.Model):
  8. __tablename__ = "doc_category"
  9. __table_args__ = (
  10. CheckConstraint(
  11. "category_type IN ('SCENE', 'STYLE', 'SITUATION', 'VERSION', 'OTHER')",
  12. name="category_type",
  13. ),
  14. CheckConstraint(
  15. "status IN ('ENABLED', 'DISABLED')",
  16. name="category_status",
  17. ),
  18. Index(
  19. "ix_doc_category_parent_active_sort",
  20. "parent_id",
  21. "is_deleted",
  22. "sort_no",
  23. ),
  24. Index(
  25. "ix_doc_category_status_active",
  26. "status",
  27. "is_deleted",
  28. ),
  29. Index(
  30. "ix_doc_category_type_active",
  31. "category_type",
  32. "is_deleted",
  33. ),
  34. )
  35. parent_id: Mapped[int | None] = mapped_column(
  36. BigInteger,
  37. ForeignKey("doc_category.id", ondelete="RESTRICT"),
  38. nullable=True,
  39. )
  40. category_code: Mapped[str] = mapped_column(
  41. String(64),
  42. nullable=False,
  43. unique=True,
  44. )
  45. category_name: Mapped[str] = mapped_column(String(128), nullable=False)
  46. category_type: Mapped[str] = mapped_column(
  47. String(32),
  48. nullable=False,
  49. server_default=text("'OTHER'"),
  50. )
  51. category_path: Mapped[str] = mapped_column(String(1000), nullable=False)
  52. sort_no: Mapped[int] = mapped_column(
  53. Integer,
  54. nullable=False,
  55. server_default=text("0"),
  56. )
  57. document_count: Mapped[int] = mapped_column(
  58. Integer,
  59. nullable=False,
  60. server_default=text("0"),
  61. )
  62. status: Mapped[str] = mapped_column(
  63. String(20),
  64. nullable=False,
  65. server_default=text("'ENABLED'"),
  66. )