AP1.10a: Initiative-Standardfelder vision, Zielzustand und Archetyp-Schlüssel.
Deploy Development / deploy (push) Successful in 45s
Test Suite / pytest-backend (push) Successful in 1m51s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 12s

Migration 016, Archetyp-Registry-API, erweitertes Profil-Modal und Plan-Profil-Ansicht.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
LarsandCursor committed 2026-07-09 11:48:54 +02:00
1 parent 495993cad6
commit 408050bcb8
14 files changed
+342 -40

No files matched your search

+48 -14
View File
@@ -7,6 +7,7 @@ from typing import Any, Literal, Optional
from psycopg2.extras import RealDictCursor
from db import get_connection
from entity_archetypes import validate_archetype_key
from services.audit import log_audit
InitiativeStatus = Literal["active", "paused", "completed", "archived"]
@@ -15,6 +16,11 @@ Priority = Literal["low", "normal", "high"]
INITIATIVE_STATUSES = frozenset({"active", "paused", "completed", "archived"})
PRIORITIES = frozenset({"low", "normal", "high"})
_INITIATIVE_COLUMNS = """
id, tenant_id, title, goal, vision, target_state_summary, archetype_key,
status, priority, owner_actor_id, created_at, updated_at
"""
def _serialize_row(row: dict[str, Any]) -> dict[str, Any]:
result = dict(row)
@@ -51,12 +57,19 @@ def _actor_in_tenant(*, tenant_id: str, actor_id: str) -> bool:
conn.close()
def _validate_archetype_key(archetype_key: str) -> None:
validate_archetype_key(entity_type="initiative", archetype_key=archetype_key)
def create_initiative(
*,
tenant_id: str,
title: str,
owner_actor_id: str,
goal: str = "",
vision: str = "",
target_state_summary: str = "",
archetype_key: str = "initiative.generic",
status: InitiativeStatus = "active",
priority: Priority = "normal",
user_id: Optional[str] = None,
@@ -66,6 +79,7 @@ def create_initiative(
raise ValueError("Titel ist erforderlich")
_validate_initiative_status(status)
_validate_priority(priority)
_validate_archetype_key(archetype_key)
if not _actor_in_tenant(tenant_id=tenant_id, actor_id=owner_actor_id):
raise ValueError("Owner-Actor gehört nicht zum Tenant")
@@ -73,15 +87,25 @@ def create_initiative(
try:
with conn.cursor(cursor_factory=RealDictCursor) as cur:
cur.execute(
"""
f"""
INSERT INTO initiatives (
tenant_id, title, goal, status, priority, owner_actor_id
tenant_id, title, goal, vision, target_state_summary, archetype_key,
status, priority, owner_actor_id
)
VALUES (%s, %s, %s, %s, %s, %s)
RETURNING id, tenant_id, title, goal, status, priority,
owner_actor_id, created_at, updated_at
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
RETURNING {_INITIATIVE_COLUMNS}
""",
(tenant_id, title, goal, status, priority, owner_actor_id),
(
tenant_id,
title,
goal,
vision,
target_state_summary,
archetype_key,
status,
priority,
owner_actor_id,
),
)
row = _serialize_row(dict(cur.fetchone()))
conn.commit()
@@ -109,9 +133,8 @@ def list_initiatives(*, tenant_id: str) -> list[dict[str, Any]]:
try:
with conn.cursor(cursor_factory=RealDictCursor) as cur:
cur.execute(
"""
SELECT id, tenant_id, title, goal, status, priority,
owner_actor_id, created_at, updated_at
f"""
SELECT {_INITIATIVE_COLUMNS}
FROM initiatives
WHERE tenant_id = %s
ORDER BY updated_at DESC, title
@@ -128,9 +151,8 @@ def get_initiative(*, tenant_id: str, initiative_id: str) -> Optional[dict[str,
try:
with conn.cursor(cursor_factory=RealDictCursor) as cur:
cur.execute(
"""
SELECT id, tenant_id, title, goal, status, priority,
owner_actor_id, created_at, updated_at
f"""
SELECT {_INITIATIVE_COLUMNS}
FROM initiatives
WHERE id = %s AND tenant_id = %s
""",
@@ -149,6 +171,9 @@ def update_initiative(
user_id: Optional[str] = None,
title: Optional[str] = None,
goal: Optional[str] = None,
vision: Optional[str] = None,
target_state_summary: Optional[str] = None,
archetype_key: Optional[str] = None,
status: Optional[InitiativeStatus] = None,
priority: Optional[Priority] = None,
owner_actor_id: Optional[str] = None,
@@ -170,6 +195,16 @@ def update_initiative(
if goal is not None:
updates.append("goal = %s")
params.append(goal)
if vision is not None:
updates.append("vision = %s")
params.append(vision)
if target_state_summary is not None:
updates.append("target_state_summary = %s")
params.append(target_state_summary)
if archetype_key is not None:
_validate_archetype_key(archetype_key)
updates.append("archetype_key = %s")
params.append(archetype_key)
if status is not None:
_validate_initiative_status(status)
updates.append("status = %s")
@@ -198,8 +233,7 @@ def update_initiative(
UPDATE initiatives
SET {", ".join(updates)}
WHERE id = %s AND tenant_id = %s
RETURNING id, tenant_id, title, goal, status, priority,
owner_actor_id, created_at, updated_at
RETURNING {_INITIATIVE_COLUMNS}
""",
params,
)