| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- """方案关联关系模型(方案与其关联方案间的有向声明)。"""
- 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 DocumentRelation(BusinessTableMixin, db.Model):
- __tablename__ = "doc_document_relation"
- __table_args__ = (
- CheckConstraint(
- "document_id <> related_document_id",
- name="document_relation_no_self",
- ),
- UniqueConstraint(
- "document_id",
- "related_document_id",
- "active_marker",
- name="uq_doc_document_relation_active",
- ),
- Index(
- "ix_doc_document_relation_document_active_sort",
- "document_id",
- "is_deleted",
- "sort_no",
- ),
- Index(
- "ix_doc_document_relation_related_active",
- "related_document_id",
- "is_deleted",
- ),
- )
- document_id: Mapped[int] = mapped_column(
- BigInteger,
- ForeignKey("doc_document.id", ondelete="RESTRICT"),
- nullable=False,
- )
- related_document_id: Mapped[int] = mapped_column(
- BigInteger,
- ForeignKey("doc_document.id", ondelete="RESTRICT"),
- nullable=False,
- )
- relation_type: Mapped[str] = mapped_column(String(64), nullable=False)
- sort_no: Mapped[int] = mapped_column(
- Integer,
- nullable=False,
- server_default=text("0"),
- )
- active_marker: Mapped[int | None] = mapped_column(
- Integer,
- Computed("IF(is_deleted = 0, 1, NULL)", persisted=False),
- nullable=True,
- )
|