feat: add project-scoped operations
Generic Container CI/CD / test-build-publish (push) Failing after 6s
Server CI/CD v2 / build-test-publish-and-deploy (push) Failing after 6s

This commit is contained in:
2026-10-22 18:40:20 +08:00
parent d320972d57
commit 1d061f6099
73 changed files with 4384 additions and 228 deletions
+1
View File
@@ -43,6 +43,7 @@ class Project(Base):
description: Mapped[str | None] = mapped_column(Text, nullable=True)
gs_workspace: Mapped[str] = mapped_column(String(100), unique=True)
map_extent: Mapped[dict | None] = mapped_column(JSONB, nullable=True)
map_config: Mapped[dict] = mapped_column(JSONB, nullable=False, default=dict, server_default="{}")
status: Mapped[str] = mapped_column(String(20), default="active")
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=datetime.utcnow
@@ -1,4 +1,4 @@
from dataclasses import dataclass
from dataclasses import dataclass, field
from datetime import datetime, timezone
from typing import Optional, List
from uuid import UUID, uuid4
@@ -66,6 +66,7 @@ class ProjectDetail:
gs_workspace: str
map_extent: Optional[dict]
status: str
map_config: dict = field(default_factory=dict)
@dataclass(frozen=True)
@@ -221,6 +222,7 @@ class MetadataRepository:
map_extent: dict | None,
status: str,
creator_user_id: UUID | None = None,
map_config: dict | None = None,
) -> models.Project:
project = models.Project(
id=uuid4(),
@@ -230,6 +232,7 @@ class MetadataRepository:
gs_workspace=gs_workspace,
map_extent=map_extent,
status=status,
map_config=map_config or {},
created_at=_utcnow(),
updated_at=_utcnow(),
)
@@ -272,6 +275,7 @@ class MetadataRepository:
gs_workspace=gs_workspace,
map_extent=map_extent,
status="active",
map_config={},
created_at=_utcnow(),
updated_at=_utcnow(),
)
@@ -327,6 +331,8 @@ class MetadataRepository:
):
if field in updates:
setattr(project, field, updates[field])
if "map_config" in updates:
project.map_config = {**(project.map_config or {}), **updates["map_config"]}
project.updated_at = _utcnow()
await self.session.commit()
await self.session.refresh(project)
@@ -343,6 +349,7 @@ class MetadataRepository:
description=project.description,
gs_workspace=project.gs_workspace,
map_extent=project.map_extent,
map_config=project.map_config or {},
status=project.status,
)
+7
View File
@@ -89,3 +89,10 @@ class McpQueryRepository:
"SELECT pg_advisory_xact_lock(hashtextextended(%s,0))",
(f"mcp:{self.project_id}:{scope_key}:{call_id}",),
)
async def finish_receipt(self, scope_key: str, call_id: str, result: dict):
async with self.conn.cursor() as cur:
await cur.execute(
"UPDATE workbench.mcp_query_receipts SET result=%s WHERE project_id=%s AND scope_key=%s AND call_id=%s",
(Jsonb(result), self.project_id, scope_key, call_id),
)
+8 -9
View File
@@ -12,20 +12,19 @@ async def lock_event_transaction(connection: AsyncConnection) -> None:
PostgreSQL sequence allocation is not commit order. All producers must use
this same transaction lock so a committed higher cursor cannot hide an
earlier, still-uncommitted event. Other BizDBs remain rollout opt-out.
earlier, still-uncommitted event. The lock is local to the connected BizDB
and creates no schema or data in projects without an event log.
"""
if getattr(getattr(connection, "info", None), "dbname", None) == "tjwater_v2":
await connection.execute(
"SELECT pg_advisory_xact_lock(hashtextextended(%s,0))", (EVENT_ORDER_LOCK,)
)
await connection.execute(
"SELECT pg_advisory_xact_lock(hashtextextended(%s,0))", (EVENT_ORDER_LOCK,)
)
def lock_event_transaction_sync(connection: Connection) -> None:
"""Synchronous counterpart using the identical PostgreSQL lock key."""
if getattr(getattr(connection, "info", None), "dbname", None) == "tjwater_v2":
connection.execute(
"SELECT pg_advisory_xact_lock(hashtextextended(%s,0))", (EVENT_ORDER_LOCK,)
)
connection.execute(
"SELECT pg_advisory_xact_lock(hashtextextended(%s,0))", (EVENT_ORDER_LOCK,)
)
class WorkbenchEventRepository:
@@ -46,6 +46,25 @@ class ScadaRepository:
)
return await cur.fetchall()
@staticmethod
async def get_latest_scada_readings(
conn: AsyncConnection,
device_ids: List[str],
) -> dict[str, dict[str, Any]]:
"""Return at most one latest row for each requested canonical device ID."""
if not device_ids:
return {}
async with conn.cursor() as cur:
await cur.execute(
f"SELECT DISTINCT ON (device_id) {ScadaRepository.RESULT_COLUMNS} "
"FROM scada.measurements WHERE device_id = ANY(%s) "
"ORDER BY device_id, time DESC",
(device_ids,),
)
rows = await cur.fetchall()
return {str(row["device_id"]): dict(row) for row in rows}
@staticmethod
def get_scada_by_ids_time_range_sync(
conn: Connection,
+1 -1
View File
@@ -84,7 +84,7 @@ class Output:
def units(self) -> dict[str, str]:
f_us = ["CFS", "GPM", "MGD", "IMGD", "AFD", "LPS", "LPM", "MLD", "CMH", "CMD"]
p_us = ["PSI", "MTR", "KPA"]
p_us = ["PSI", "KPA", "MTR"]
q_us = ["NONE", "MGL", "UGL", "HOURS", "PRCNT"]
f, p, q = ctypes.c_int(1), ctypes.c_int(2), ctypes.c_int(3)
f_u, p_u, q_u = ctypes.c_int(), ctypes.c_int(), ctypes.c_int()