Implement flexible entity relation system (Phases A–E)
Declarative relation registry via defrelation s-expressions with cardinality enforcement (one-to-one, one-to-many, many-to-many), registry-aware relate/unrelate/can-relate API endpoints, generic container-nav fragment, and relation-driven UI components. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy import Integer, String, DateTime, Index, UniqueConstraint, func
|
||||
from sqlalchemy import Integer, String, DateTime, Index, JSON, UniqueConstraint, func
|
||||
from shared.db.base import Base
|
||||
|
||||
|
||||
@@ -15,6 +15,10 @@ class ContainerRelation(Base):
|
||||
),
|
||||
Index("ix_container_relations_parent", "parent_type", "parent_id"),
|
||||
Index("ix_container_relations_child", "child_type", "child_id"),
|
||||
Index(
|
||||
"ix_container_relations_relation_type",
|
||||
"relation_type", "parent_type", "parent_id",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
@@ -24,6 +28,9 @@ class ContainerRelation(Base):
|
||||
child_type: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
child_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
|
||||
relation_type: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, index=False)
|
||||
metadata_: Mapped[Optional[dict]] = mapped_column("metadata", JSON, nullable=True)
|
||||
|
||||
sort_order: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
label: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user