organization.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """组织机构模型。"""
  2. from __future__ import annotations
  3. from sqlalchemy import BigInteger, CheckConstraint, ForeignKey, Index, 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 Organization(BusinessTableMixin, db.Model):
  8. __tablename__ = "sys_organization"
  9. __table_args__ = (
  10. CheckConstraint(
  11. "status IN ('ENABLED', 'DISABLED')",
  12. name="organization_status",
  13. ),
  14. Index(
  15. "ix_sys_organization_parent_active_sort",
  16. "parent_id",
  17. "is_deleted",
  18. "sort_no",
  19. ),
  20. Index(
  21. "ix_sys_organization_status_active",
  22. "status",
  23. "is_deleted",
  24. ),
  25. )
  26. parent_id: Mapped[int | None] = mapped_column(
  27. BigInteger,
  28. ForeignKey("sys_organization.id", ondelete="RESTRICT"),
  29. nullable=True,
  30. )
  31. org_code: Mapped[str] = mapped_column(String(64), nullable=False, unique=True)
  32. org_name: Mapped[str] = mapped_column(String(128), nullable=False)
  33. org_path: Mapped[str] = mapped_column(String(1000), nullable=False)
  34. sort_no: Mapped[int] = mapped_column(nullable=False, server_default=text("0"))
  35. status: Mapped[str] = mapped_column(
  36. String(20),
  37. nullable=False,
  38. server_default=text("'ENABLED'"),
  39. )