chore(ops): test-data cleanup script and runbook

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 11:14:57 +08:00
co-authored by Claude Sonnet 5.5
parent 1b84ed8625
commit 10f22b5cd5
3 changed files with 92 additions and 4 deletions
@@ -32,17 +32,16 @@ Making zone optional; a "General" zone per site.
- Allowed: CAPA owner, or hse/admin. Status must be `in_progress`; otherwise 409.
- Validates note non-empty and 1 to 5 image files; otherwise 422.
- In one `withUser` transaction: store files via `lib/storage/evidence.ts`, insert `evidence_files` rows (`stage = 'capa'`, `capa_id` set, hash recorded), set `owner_notes`, `completed_at`, `status = 'pending_verification'`, and write `audit_log` (include file ids and the note).
- Existing in-app notification to HSE on submission is kept.
- `PATCH /api/capa/[id]` rejects `status: 'pending_verification'` with 403 for everyone (the new endpoint is the only path). Owner `in_progress` transition is unchanged.
- CAPA detail page: "Completion report" section shows the note and a photo gallery (signed `/api/evidence/...` URLs) so HSE sees proof when verifying or reopening.
- Evidence rows are never hard-deleted (5-year retention).
### Schema change (manual, needs owner go-ahead)
```sql
ALTER TABLE evidence_files ADD COLUMN capa_id uuid REFERENCES capa_actions(id);
CREATE INDEX evidence_files_capa_id_idx ON evidence_files(capa_id);
ALTER TABLE evidence_files ADD COLUMN IF NOT EXISTS capa_id UUID REFERENCES capa_actions(id) ON DELETE RESTRICT;
CREATE INDEX IF NOT EXISTS evidence_files_capa_id_idx ON evidence_files(capa_id);
```
The `evidence_stage` enum already has `capa`; no enum change. Update `db/schema.sql`, `lib/db/schema.ts`, and check the `evidence_*` RLS policies in `db/rls.sql` cover CAPA owners (insert) and hse/admin (read); add a read policy for the CAPA owner if missing.
The `evidence_stage` enum already has `capa`; no enum change. Update `db/schema.sql`, `lib/db/schema.ts`, no RLS change: the PIC is the uploader and already reads own rows.
### Out of scope
Photos on "Mark In Progress"; HSE-side evidence upload; video.