phase: 02-operations-maintenance
plan: "02"
subsystem: api
tags: [fastapi, psycopg2, postgres, pgvector, admin]

requires:
- phase: 02-01
provides: DB_URL env var and psycopg2 health-check pattern in api.py

provides:
- POST /admin/reset endpoint that deletes all chunks and returns the deleted count

affects: [query, ingest]

tech-stack:
added: []
patterns:
- "SELECT COUNT(*) before DELETE FROM to capture row count for response"
- "Admin maintenance endpoints follow same inline psycopg2 connect/close pattern as /health"

key-files:
created: []
modified:
- api.py

key-decisions:
- "DELETE FROM chunks instead of TRUNCATE: avoids elevated privileges, easier rollback"
- "SELECT COUNT(*) before DELETE: captures exact deleted count for response without relying on rowcount"

patterns-established:
- "ResetResponse(deleted, message): standard shape for destructive admin endpoints"

requirements-completed: [OPS-01]

duration: 1min
completed: 2026-03-24


Phase 02 Plan 02: Admin Reset Endpoint Summary

POST /admin/reset added to api.py: deletes all chunks rows via psycopg2 DELETE and returns deleted count with German message

Performance

  • Duration: 1 min
  • Started: 2026-03-24T17:43:08Z
  • Completed: 2026-03-24T17:43:39Z
  • Tasks: 1
  • Files modified: 1

Accomplishments

  • Added ResetResponse Pydantic model with deleted: int and message: str fields
  • Added POST /admin/reset route that counts, deletes, and commits all chunks rows
  • Crew can now wipe the knowledge base via a single API call without direct DB access

Task Commits

Each task was committed atomically:

  1. Task 1: Add POST /admin/reset endpoint - 974d638 (feat)

Files Created/Modified

  • api.py - Added ResetResponse model and /admin/reset route after /query, before /health

Decisions Made

  • DELETE FROM instead of TRUNCATE: avoids elevated privilege requirements and works within standard user grants
  • SELECT COUNT(*) first, then DELETE: ensures returned count is accurate (not relying on cursor.rowcount)

Deviations from Plan

None - plan executed exactly as written.

Issues Encountered

None.

User Setup Required

None - no external service configuration required.

Next Phase Readiness

  • /admin/reset is ready for immediate use via curl -X POST http://localhost:8080/admin/reset
  • No blockers for remaining phase plans

Phase: 02-operations-maintenance
Completed: 2026-03-24