Skip to content

Commit fc1d48e

Browse files
committed
arch(db): add tool_sop and reference
1 parent c9a483c commit fc1d48e

4 files changed

Lines changed: 76 additions & 3 deletions

File tree

src/server/core/acontext_core/schema/orm/block.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
if TYPE_CHECKING:
1919
from .space import Space
20+
from .tool_sop import ToolSOP
2021

2122

2223
# Block type configuration matching Go version
@@ -193,6 +194,15 @@ class Block(CommonMixin):
193194
},
194195
)
195196

197+
tool_sops: List["ToolSOP"] = field(
198+
default_factory=list,
199+
metadata={
200+
"db": relationship(
201+
"ToolSOP", back_populates="sop_block", cascade="all, delete-orphan"
202+
)
203+
},
204+
)
205+
196206
def validate(self) -> None:
197207
"""Validate the fields of a Block"""
198208
# Check if the type is valid

src/server/core/acontext_core/schema/orm/project.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
if TYPE_CHECKING:
1010
from .space import Space
1111
from .session import Session
12+
from .tool_reference import ToolReference
1213

1314

1415
@ORM_BASE.mapped
@@ -47,3 +48,12 @@ class Project(CommonMixin):
4748
)
4849
},
4950
)
51+
52+
tool_references: List["ToolReference"] = field(
53+
default_factory=list,
54+
metadata={
55+
"db": relationship(
56+
"ToolReference", back_populates="project", cascade="all, delete-orphan"
57+
)
58+
},
59+
)

src/server/core/acontext_core/schema/orm/tool_reference.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .space import Space
1212
from .message import Message
1313
from .task import Task
14+
from .tool_sop import ToolSOP
1415

1516

1617
@ORM_BASE.mapped
@@ -36,14 +37,15 @@ class ToolReference(CommonMixin):
3637

3738
# Relationships
3839
project: "Project" = field(
39-
init=False, metadata={"db": relationship("Project", back_populates="sessions")}
40+
init=False,
41+
metadata={"db": relationship("Project", back_populates="tool_references")},
4042
)
4143

42-
tasks: List["Task"] = field(
44+
tool_sops: List["ToolSOP"] = field(
4345
default_factory=list,
4446
metadata={
4547
"db": relationship(
46-
"Task", back_populates="session", cascade="all, delete-orphan"
48+
"ToolSOP", back_populates="tool_reference", cascade="all, delete-orphan"
4749
)
4850
},
4951
)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from dataclasses import dataclass, field
2+
from sqlalchemy import ForeignKey, Index, Column, String
3+
from sqlalchemy.orm import relationship
4+
from sqlalchemy.dialects.postgresql import JSONB, UUID
5+
from typing import TYPE_CHECKING, Optional, List
6+
from .base import ORM_BASE, CommonMixin
7+
from ..utils import asUUID
8+
9+
if TYPE_CHECKING:
10+
from .project import Project
11+
from .tool_reference import ToolReference
12+
from .block import Block
13+
14+
15+
@ORM_BASE.mapped
16+
@dataclass
17+
class ToolSOP(CommonMixin):
18+
__tablename__ = "tool_sops"
19+
20+
__table_args__ = (Index("ix_tool_sop_project_id", "project_id"),)
21+
22+
annotation: str = field(metadata={"db": Column(String, nullable=False)})
23+
24+
tool_id: asUUID = field(
25+
metadata={
26+
"db": Column(
27+
UUID(as_uuid=True),
28+
ForeignKey("tool_references.id", ondelete="CASCADE"),
29+
nullable=False,
30+
)
31+
}
32+
)
33+
sop_block_id: asUUID = field(
34+
metadata={
35+
"db": Column(
36+
UUID(as_uuid=True),
37+
ForeignKey("blocks.id", ondelete="CASCADE"),
38+
nullable=False,
39+
)
40+
}
41+
)
42+
43+
# Relationships
44+
tool_reference: "ToolReference" = field(
45+
init=False,
46+
metadata={"db": relationship("ToolReference", back_populates="tool_sops")},
47+
)
48+
sop_block: "Block" = field(
49+
init=False,
50+
metadata={"db": relationship("Block", back_populates="tool_sops")},
51+
)

0 commit comments

Comments
 (0)