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';
