CREATE TABLE IF NOT EXISTS rag_ocr_recovery_audit ( recovery_id uuid PRIMARY KEY DEFAULT gen_random_uuid(), version_id uuid NOT NULL REFERENCES rag_source_versions(version_id) ON DELETE RESTRICT, recovered_by text NOT NULL, reason text NOT NULL, outcome text NOT NULL CHECK (outcome IN ('closed_failed')), error_code text NOT NULL, created_at timestamptz NOT NULL DEFAULT now() );