🌐 Cloud-Native Architecture: - Firebase Functions deployment (no Docker) - Supabase database (replacing local PostgreSQL) - Google Cloud Storage integration - Document AI + Agentic RAG processing pipeline - Claude-3.5-Sonnet LLM integration ✅ Full BPCP CIM Review Template (7 sections): - Deal Overview - Business Description - Market & Industry Analysis - Financial Summary (with historical financials table) - Management Team Overview - Preliminary Investment Thesis - Key Questions & Next Steps 🔧 Cloud Migration Improvements: - PostgreSQL → Supabase migration complete - Local storage → Google Cloud Storage - Docker deployment → Firebase Functions - Schema mapping fixes (camelCase/snake_case) - Enhanced error handling and logging - Vector database with fallback mechanisms 📄 Complete End-to-End Cloud Workflow: 1. Upload PDF → Document AI extraction 2. Agentic RAG processing → Structured CIM data 3. Store in Supabase → Vector embeddings 4. Auto-generate PDF → Full BPCP template 5. Download complete CIM review 🚀 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
112 lines
3.8 KiB
JavaScript
112 lines
3.8 KiB
JavaScript
const { createClient } = require('@supabase/supabase-js');
|
|
|
|
// Load environment variables
|
|
require('dotenv').config();
|
|
|
|
const supabaseUrl = process.env.SUPABASE_URL;
|
|
const supabaseServiceKey = process.env.SUPABASE_SERVICE_KEY;
|
|
|
|
const supabase = createClient(supabaseUrl, supabaseServiceKey);
|
|
|
|
async function testAndCreateTable() {
|
|
console.log('🔍 Testing Supabase connection...');
|
|
|
|
// First, test if we can connect
|
|
const { data: testData, error: testError } = await supabase
|
|
.from('_test_table_that_does_not_exist')
|
|
.select('*')
|
|
.limit(1);
|
|
|
|
if (testError) {
|
|
console.log('✅ Connection works (expected error for non-existent table)');
|
|
console.log('Error:', testError.message);
|
|
}
|
|
|
|
// Try to see what tables exist
|
|
console.log('🔍 Checking existing tables...');
|
|
|
|
// Check if document_chunks already exists
|
|
const { data: chunksData, error: chunksError } = await supabase
|
|
.from('document_chunks')
|
|
.select('*')
|
|
.limit(1);
|
|
|
|
if (chunksError) {
|
|
console.log('❌ document_chunks table does not exist');
|
|
console.log('Error:', chunksError.message);
|
|
|
|
if (chunksError.code === 'PGRST106') {
|
|
console.log('📝 Table needs to be created in Supabase dashboard');
|
|
console.log('');
|
|
console.log('🛠️ Please create the table manually in Supabase:');
|
|
console.log('1. Go to https://supabase.com/dashboard');
|
|
console.log('2. Select your project: cim-summarizer');
|
|
console.log('3. Go to SQL Editor');
|
|
console.log('4. Run this SQL:');
|
|
console.log('');
|
|
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 indexes
|
|
CREATE INDEX idx_document_chunks_document_id ON document_chunks(document_id);
|
|
CREATE INDEX idx_document_chunks_chunk_index ON document_chunks(chunk_index);
|
|
|
|
-- Enable RLS
|
|
ALTER TABLE document_chunks ENABLE ROW LEVEL SECURITY;
|
|
|
|
-- Create policies
|
|
CREATE POLICY "Enable all operations for service role" ON document_chunks
|
|
FOR ALL USING (true);`);
|
|
}
|
|
} else {
|
|
console.log('✅ document_chunks table already exists!');
|
|
console.log(`Found table with ${chunksData ? chunksData.length : 0} rows`);
|
|
}
|
|
|
|
// Test a simple insert to see if we have write permissions
|
|
console.log('🧪 Testing write permissions...');
|
|
|
|
const testChunk = {
|
|
document_id: 'test-document-id',
|
|
content: 'This is a test chunk for vector database setup',
|
|
chunk_index: 1,
|
|
metadata: { test: true }
|
|
};
|
|
|
|
const { data: insertData, error: insertError } = await supabase
|
|
.from('document_chunks')
|
|
.insert(testChunk)
|
|
.select();
|
|
|
|
if (insertError) {
|
|
console.log('❌ Insert test failed:', insertError.message);
|
|
if (insertError.code === 'PGRST106') {
|
|
console.log('Table does not exist - needs manual creation');
|
|
}
|
|
} else {
|
|
console.log('✅ Insert test successful!');
|
|
console.log('Inserted data:', insertData);
|
|
|
|
// Clean up test data
|
|
const { error: deleteError } = await supabase
|
|
.from('document_chunks')
|
|
.delete()
|
|
.eq('document_id', 'test-document-id');
|
|
|
|
if (deleteError) {
|
|
console.log('⚠️ Could not clean up test data:', deleteError.message);
|
|
} else {
|
|
console.log('🧹 Test data cleaned up');
|
|
}
|
|
}
|
|
}
|
|
|
|
testAndCreateTable(); |