const { createClient } = require('@supabase/supabase-js'); require('dotenv').config(); const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_SERVICE_KEY); async function checkTableSchema() { console.log('๐Ÿ”ง Checking document_chunks table...'); // Try to select from the table to see what columns exist const { data, error } = await supabase .from('document_chunks') .select('*') .limit(1); if (error) { console.log('โŒ Error accessing table:', error.message); if (error.message.includes('does not exist')) { console.log(''); console.log('๐Ÿ› ๏ธ Table does not exist. Need to create it with:'); console.log(` CREATE TABLE document_chunks ( id UUID DEFAULT gen_random_uuid() PRIMARY KEY, document_id TEXT NOT NULL, content TEXT NOT NULL, embedding VECTOR(1536), metadata JSONB DEFAULT '{}', chunk_index INTEGER NOT NULL, created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW() ); CREATE INDEX idx_document_chunks_document_id ON document_chunks(document_id); CREATE INDEX idx_document_chunks_embedding ON document_chunks USING ivfflat (embedding vector_cosine_ops); `); } return; } if (data && data.length > 0) { console.log('โœ… Table exists'); console.log('๐Ÿ“‹ Available columns:', Object.keys(data[0])); const hasChunkIndex = 'chunk_index' in data[0]; const hasChunkIndexCamel = 'chunkIndex' in data[0]; console.log('Has chunk_index:', hasChunkIndex); console.log('Has chunkIndex:', hasChunkIndexCamel); if (!hasChunkIndex && !hasChunkIndexCamel) { console.log('โš ๏ธ Missing chunk index column.'); console.log('๐Ÿ› ๏ธ Run this SQL to fix:'); console.log('ALTER TABLE document_chunks ADD COLUMN chunk_index INTEGER;'); } } else { console.log('๐Ÿ“‹ Table exists but is empty'); console.log('๐Ÿงช Testing insert to see schema...'); // Try to insert a test record to see what columns are expected const { error: insertError } = await supabase .from('document_chunks') .insert({ document_id: 'test', content: 'test content', chunk_index: 1, metadata: {} }) .select(); if (insertError) { console.log('โŒ Insert failed:', insertError.message); if (insertError.message.includes('chunkIndex')) { console.log('โš ๏ธ Table expects camelCase chunkIndex but code uses snake_case chunk_index'); } else if (insertError.message.includes('chunk_index')) { console.log('โš ๏ธ Missing chunk_index column'); } } else { console.log('โœ… Test insert successful'); // Clean up test record await supabase .from('document_chunks') .delete() .eq('document_id', 'test'); } } } checkTableSchema();