diff --git a/mcp-server/src/legal_mcp/services/db.py b/mcp-server/src/legal_mcp/services/db.py index 9cab861..9b45773 100644 --- a/mcp-server/src/legal_mcp/services/db.py +++ b/mcp-server/src/legal_mcp/services/db.py @@ -681,6 +681,26 @@ async def restore_case(case_id: UUID) -> dict | None: return _row_to_case(row) if row else None +async def delete_case(case_id: UUID) -> bool: + """Delete a case row. Returns True if a row was actually removed. + + All dependent rows are removed automatically by FK constraints: + • CASCADE: documents, document_chunks, claims, appraiser_facts, + decisions, qa_results, case_precedents + • SET NULL: audit_log.case_id, chair_feedback.case_id + + NOTE: this only touches the legal-ai database. The Paperclip project + (issues, comments, runs) and Gitea repo for the case live in other + systems and are NOT cleaned up here — call sites that need a full + reset must handle those separately. + """ + pool = await get_pool() + async with pool.acquire() as conn: + result = await conn.execute("DELETE FROM cases WHERE id = $1", case_id) + # asyncpg execute returns "DELETE " — extract count. + return int(result.split()[-1]) > 0 + + # ── Document CRUD ─────────────────────────────────────────────────── async def create_document(