| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- """组织机构模型。"""
- from __future__ import annotations
- from sqlalchemy import (
- BigInteger,
- CheckConstraint,
- Computed,
- ForeignKey,
- Index,
- Integer,
- String,
- UniqueConstraint,
- text,
- )
- from sqlalchemy.orm import Mapped, mapped_column
- from dms.database.base import BusinessTableMixin
- from dms.extensions import db
- class Organization(BusinessTableMixin, db.Model):
- __tablename__ = "sys_organization"
- __table_args__ = (
- UniqueConstraint(
- "org_code",
- "active_marker",
- name="uq_sys_organization_org_code_active",
- ),
- CheckConstraint(
- "status IN ('ENABLED', 'DISABLED')",
- name="organization_status",
- ),
- Index(
- "ix_sys_organization_parent_active_sort",
- "parent_id",
- "is_deleted",
- "sort_no",
- ),
- Index(
- "ix_sys_organization_status_active",
- "status",
- "is_deleted",
- ),
- )
- parent_id: Mapped[int | None] = mapped_column(
- BigInteger,
- ForeignKey("sys_organization.id", ondelete="RESTRICT"),
- nullable=True,
- )
- org_code: Mapped[str] = mapped_column(String(64), nullable=False)
- org_name: Mapped[str] = mapped_column(String(128), nullable=False)
- org_path: Mapped[str] = mapped_column(String(1000), nullable=False)
- sort_no: Mapped[int] = mapped_column(nullable=False, server_default=text("0"))
- status: Mapped[str] = mapped_column(
- String(20),
- nullable=False,
- server_default=text("'ENABLED'"),
- )
- active_marker: Mapped[int | None] = mapped_column(
- Integer,
- Computed("IF(is_deleted = 0, 1, NULL)", persisted=False),
- nullable=True,
- )
|