diff --git a/migrations/20250702000001_add_ocr_retry_fields.sql b/migrations/20250702000001_add_ocr_retry_fields.sql new file mode 100644 index 0000000..e63d3c1 --- /dev/null +++ b/migrations/20250702000001_add_ocr_retry_fields.sql @@ -0,0 +1,9 @@ +-- Add OCR retry tracking fields to documents table +-- These fields were added to the Document struct but missing from the database schema + +ALTER TABLE documents ADD COLUMN IF NOT EXISTS ocr_retry_count INTEGER DEFAULT 0; +ALTER TABLE documents ADD COLUMN IF NOT EXISTS ocr_failure_reason TEXT DEFAULT NULL; + +-- Add helpful comments +COMMENT ON COLUMN documents.ocr_retry_count IS 'Number of times OCR processing has been retried for this document'; +COMMENT ON COLUMN documents.ocr_failure_reason IS 'Reason for the most recent OCR failure, if any'; \ No newline at end of file diff --git a/src/db/documents.rs b/src/db/documents.rs index 561e810..1e73a31 100644 --- a/src/db/documents.rs +++ b/src/db/documents.rs @@ -29,6 +29,8 @@ impl Database { .bind(&document.ocr_status) .bind(&document.ocr_error) .bind(document.ocr_completed_at) + .bind(document.ocr_retry_count) + .bind(&document.ocr_failure_reason) .bind(&document.tags) .bind(document.created_at) .bind(document.updated_at) @@ -36,8 +38,6 @@ impl Database { .bind(&document.file_hash) .bind(document.original_created_at) .bind(document.original_modified_at) - .bind(document.ocr_retry_count) - .bind(&document.ocr_failure_reason) .bind(&document.source_metadata) .fetch_one(&self.pool) .await?; diff --git a/tests/integration_debug_ocr_test.rs b/tests/integration_debug_ocr_test.rs index d726fbd..0ce3ad0 100644 --- a/tests/integration_debug_ocr_test.rs +++ b/tests/integration_debug_ocr_test.rs @@ -109,6 +109,13 @@ async fn debug_ocr_content() { .await .expect("Upload should work"); + println!("📤 Document 1 upload response status: {}", doc1_response.status()); + if !doc1_response.status().is_success() { + let status = doc1_response.status(); + let error_text = doc1_response.text().await.unwrap_or_else(|_| "No response body".to_string()); + panic!("Document 1 upload failed with status {}: {}", status, error_text); + } + let doc2_response = client .post(&format!("{}/api/documents", get_base_url())) .header("Authorization", format!("Bearer {}", token)) @@ -117,8 +124,15 @@ async fn debug_ocr_content() { .await .expect("Upload should work"); - let doc1: DocumentResponse = doc1_response.json().await.expect("Valid JSON"); - let doc2: DocumentResponse = doc2_response.json().await.expect("Valid JSON"); + println!("📤 Document 2 upload response status: {}", doc2_response.status()); + if !doc2_response.status().is_success() { + let status = doc2_response.status(); + let error_text = doc2_response.text().await.unwrap_or_else(|_| "No response body".to_string()); + panic!("Document 2 upload failed with status {}: {}", status, error_text); + } + + let doc1: DocumentResponse = doc1_response.json().await.expect("Valid JSON for doc1"); + let doc2: DocumentResponse = doc2_response.json().await.expect("Valid JSON for doc2"); println!("📄 Document 1: {}", doc1.id); println!("📄 Document 2: {}", doc2.id);