-- Find all documents that need processing
-- Run this to see what documents exist and their status

-- All documents in processing status
SELECT 
  id,
  user_id,
  status,
  original_file_name,
  created_at,
  updated_at
FROM documents
WHERE status IN ('processing', 'processing_llm', 'uploading', 'extracting_text')
ORDER BY updated_at DESC;

-- Count by status
SELECT 
  status,
  COUNT(*) as count
FROM documents
GROUP BY status
ORDER BY count DESC;

-- Documents stuck in processing (updated more than 10 minutes ago)
SELECT 
  id,
  user_id,
  status,
  original_file_name,
  updated_at,
  NOW() - updated_at as time_since_update
FROM documents
WHERE status IN ('processing', 'processing_llm')
  AND updated_at < NOW() - INTERVAL '10 minutes'
ORDER BY updated_at ASC;

