kin: auto-commit after pipeline

This commit is contained in:
Gros Frumos 2026-03-17 22:41:47 +02:00
parent e8f702191f
commit 95ba853b49
3 changed files with 489 additions and 1 deletions

View file

@ -103,7 +103,26 @@ def get_project(conn: sqlite3.Connection, id: str) -> dict | None:
def delete_project(conn: sqlite3.Connection, id: str) -> None:
"""Delete a project and all its related data (modules, decisions, tasks, phases)."""
# Delete tables that have FK references to tasks BEFORE deleting tasks
# Delete child tables that reference pipelines/tasks without ON DELETE CASCADE,
# before their parents are deleted (FK constraint enforcement, foreign_keys=ON).
conn.execute(
"DELETE FROM department_handoffs WHERE task_id IN (SELECT id FROM tasks WHERE project_id = ?)",
(id,),
)
conn.execute(
"DELETE FROM department_handoffs WHERE pipeline_id IN (SELECT id FROM pipelines WHERE project_id = ?)",
(id,),
)
conn.execute(
"DELETE FROM pipeline_log WHERE pipeline_id IN (SELECT id FROM pipelines WHERE project_id = ?)",
(id,),
)
conn.execute("DELETE FROM audit_log WHERE project_id = ?", (id,))
conn.execute("DELETE FROM support_tickets WHERE project_id = ?", (id,))
conn.execute("DELETE FROM hook_logs WHERE project_id = ?", (id,))
conn.execute("DELETE FROM hooks WHERE project_id = ?", (id,))
conn.execute("DELETE FROM project_links WHERE from_project = ? OR to_project = ?", (id, id))
# Delete tables with direct project_id FK (order: FK children before parents)
# project_environments must come before tasks (FK on project_id)
for table in ("modules", "agent_logs", "decisions", "pipelines", "project_phases", "project_environments", "chat_messages", "tasks"):
conn.execute(f"DELETE FROM {table} WHERE project_id = ?", (id,))