Files
cim_summary/backend/create-missing-tables.js
Jon 185c780486
Some checks failed
CI/CD Pipeline / Backend - Lint & Test (push) Has been cancelled
CI/CD Pipeline / Frontend - Lint & Test (push) Has been cancelled
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Build Backend (push) Has been cancelled
CI/CD Pipeline / Build Frontend (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Performance Tests (push) Has been cancelled
CI/CD Pipeline / Dependency Updates (push) Has been cancelled
🚀 Update to Claude 3.7 latest and fix LLM processing issues
- Updated Anthropic API to latest version (2024-01-01)
- Set Claude 3.7 Sonnet Latest as primary model
- Removed deprecated Opus 3.5 references
- Fixed LLM response validation and JSON parsing
- Improved error handling and logging
- Updated model configurations and pricing
- Enhanced document processing reliability
- Fixed TypeScript type issues
- Updated environment configuration
2025-08-17 17:31:56 -04:00

99 lines
4.0 KiB
JavaScript

#!/usr/bin/env node
const { createClient } = require('@supabase/supabase-js');
require('dotenv').config();
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseServiceKey = process.env.SUPABASE_SERVICE_KEY;
const supabase = createClient(supabaseUrl, supabaseServiceKey);
async function createMissingTables() {
console.log('🔧 Creating missing database tables...\n');
try {
// Update document_chunks table to use vector type
console.log('📋 Updating document_chunks table to use vector type...');
const { error: chunksError } = await supabase.rpc('exec_sql', {
sql: `
ALTER TABLE document_chunks
ALTER COLUMN embedding TYPE vector(1536) USING embedding::vector(1536);
`
});
if (chunksError) {
console.log(`❌ Document chunks table error: ${chunksError.message}`);
} else {
console.log('✅ Document chunks table created successfully');
}
// Create document_versions table
console.log('📋 Creating document_versions table...');
const { error: versionsError } = await supabase.rpc('exec_sql', {
sql: `
CREATE TABLE IF NOT EXISTS document_versions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
document_id UUID REFERENCES documents(id) ON DELETE CASCADE,
version_number INTEGER NOT NULL,
file_path TEXT NOT NULL,
processing_strategy VARCHAR(50),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
`
});
if (versionsError) {
console.log(`❌ Document versions table error: ${versionsError.message}`);
} else {
console.log('✅ Document versions table created successfully');
}
// Create document_feedback table
console.log('📋 Creating document_feedback table...');
const { error: feedbackError } = await supabase.rpc('exec_sql', {
sql: `
CREATE TABLE IF NOT EXISTS document_feedback (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
document_id UUID REFERENCES documents(id) ON DELETE CASCADE,
user_id VARCHAR(255) NOT NULL,
feedback_type VARCHAR(50) NOT NULL,
feedback_text TEXT,
rating INTEGER CHECK (rating >= 1 AND rating <= 5),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
`
});
if (feedbackError) {
console.log(`❌ Document feedback table error: ${feedbackError.message}`);
} else {
console.log('✅ Document feedback table created successfully');
}
// Create indexes for the new tables
console.log('📋 Creating indexes...');
const indexSql = `
CREATE INDEX IF NOT EXISTS idx_document_chunks_document_id ON document_chunks(document_id);
CREATE INDEX IF NOT EXISTS idx_document_chunks_chunk_index ON document_chunks(chunk_index);
CREATE INDEX IF NOT EXISTS idx_document_versions_document_id ON document_versions(document_id);
CREATE INDEX IF NOT EXISTS idx_document_feedback_document_id ON document_feedback(document_id);
CREATE INDEX IF NOT EXISTS idx_document_feedback_user_id ON document_feedback(user_id);
`;
const { error: indexError } = await supabase.rpc('exec_sql', { sql: indexSql });
if (indexError) {
console.log(`❌ Index creation error: ${indexError.message}`);
} else {
console.log('✅ Indexes created successfully');
}
console.log('\n🎉 All missing tables created successfully!');
} catch (error) {
console.log('❌ Error creating tables:', error.message);
}
}
createMissingTables();