feat(ocr): add training history + POST /train + GET /training-info endpoints

- OcrTrainingRun entity + V30 migration (partial unique index prevents
  concurrent runs at DB level)
- OcrTrainingService: concurrent-run guard, 5-block threshold, MDC log
  correlation, orphan recovery on ApplicationReadyEvent
- POST /api/ocr/train (ADMIN) + GET /api/ocr/training-info (ADMIN)
- TRAINING_ALREADY_RUNNING ErrorCode
- 6 OcrTrainingServiceTest + 6 OcrControllerTest tests for the new endpoints

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-13 14:47:56 +02:00
parent bc97a2dade
commit 88e005eb49
9 changed files with 493 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
CREATE TABLE ocr_training_runs (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
status VARCHAR(20) NOT NULL DEFAULT 'RUNNING',
block_count INT NOT NULL,
document_count INT NOT NULL,
model_name VARCHAR(100) NOT NULL,
error_message TEXT,
triggered_by UUID REFERENCES users(id) ON DELETE SET NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
completed_at TIMESTAMPTZ
);
-- Enforce single active run at the DB layer (application check is the UX layer)
CREATE UNIQUE INDEX idx_ocr_training_runs_one_running
ON ocr_training_runs (status)
WHERE status = 'RUNNING';