const { createClient } = require('@supabase/supabase-js'); require('dotenv').config(); const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_SERVICE_KEY); async function testChunkInsert() { console.log('๐Ÿงช Testing exact chunk insert that is failing...'); const testChunk = { document_id: 'test-doc-123', content: 'This is test content for chunk processing', chunk_index: 1, metadata: { test: true }, embedding: new Array(1536).fill(0.1) }; console.log('๐Ÿ“ค Inserting test chunk with select...'); const { data, error } = await supabase .from('document_chunks') .insert(testChunk) .select() .single(); if (error) { console.log('โŒ Insert with select failed:', error.message); console.log('Error details:', error); // Try without select console.log('๐Ÿ”„ Trying insert without select...'); const { error: insertError } = await supabase .from('document_chunks') .insert(testChunk); if (insertError) { console.log('โŒ Plain insert also failed:', insertError.message); } else { console.log('โœ… Plain insert worked'); // Now try to select it back console.log('๐Ÿ” Trying to select the inserted record...'); const { data: selectData, error: selectError } = await supabase .from('document_chunks') .select('*') .eq('document_id', 'test-doc-123') .single(); if (selectError) { console.log('โŒ Select failed:', selectError.message); } else { console.log('โœ… Select worked'); console.log('๐Ÿ“‹ Returned columns:', Object.keys(selectData)); console.log('Has chunk_index:', 'chunk_index' in selectData); console.log('chunk_index value:', selectData.chunk_index); } } } else { console.log('โœ… Insert with select worked!'); console.log('๐Ÿ“‹ Returned columns:', Object.keys(data)); console.log('Has chunk_index:', 'chunk_index' in data); console.log('chunk_index value:', data.chunk_index); } // Clean up console.log('๐Ÿงน Cleaning up test data...'); await supabase .from('document_chunks') .delete() .eq('document_id', 'test-doc-123'); } testChunkInsert();