mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-06 01:27:43 +01:00
- Move 100+ files from root to proper directories - Migration scripts → scripts/db/ - SQL files → supabase/sql/archive/ - Test/debug scripts → scripts/test/ - Documentation → docs/archive/ (organized by category) - Shell scripts → scripts/ (organized by category) - Fix test organization - Remove nested tests/unit/tests/unit/ structure - Consolidate test files to proper locations - Update documentation references - Update migration script paths in workflow docs - Update scripts/README.md with moved file notes - Delete placeholder files - Remove empty placeholder.ipynb - Result: Root directory now contains only essential config files - Result: Professional, organized codebase structure - Result: All files in proper locations per project standards See docs/CLEANUP_COMPLETE.md for full details.
93 lines
3.1 KiB
JavaScript
93 lines
3.1 KiB
JavaScript
// Complete Database Schema Fix
|
|
import { createClient } from '@supabase/supabase-js';
|
|
import { readFileSync } from 'fs';
|
|
import { join } from 'path';
|
|
|
|
const supabaseUrl = 'https://ohkueislstxomdjavyhs.supabase.co';
|
|
const supabaseKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9oa3VlaXNsc3R4b21kamF2eWhzIiwicm9sZSI6MjA2MDEyMzk1MH0.Qc6ahUbs_5BCa4csEYsBtyxNUDYb4h3Y4K_16N1DNaY';
|
|
|
|
const supabase = createClient(supabaseUrl, supabaseKey);
|
|
|
|
async function applyCompleteSchema() {
|
|
console.log('🔧 Applying complete OrangeCat database schema...\n');
|
|
|
|
try {
|
|
// 1. Check current database state
|
|
console.log('📊 Checking current database state...');
|
|
const { data: tables, error: tableError } = await supabase
|
|
.from('information_schema.tables')
|
|
.select('table_name')
|
|
.eq('table_schema', 'public');
|
|
|
|
if (tableError) {
|
|
console.log('❌ Cannot query information_schema, trying alternative method...');
|
|
} else {
|
|
console.log('Current tables:', tables?.map(t => t.table_name).join(', ') || 'none');
|
|
}
|
|
|
|
// 2. Apply essential base tables first
|
|
console.log('\n📝 Applying base schema...');
|
|
|
|
// Read and apply the consolidated schema
|
|
const schemaFiles = [
|
|
'supabase/migrations/20250924000000_consolidated_schema.sql',
|
|
'supabase/migrations/20251202_create_personal_economy_tables.sql'
|
|
];
|
|
|
|
for (const file of schemaFiles) {
|
|
try {
|
|
console.log(`📄 Applying ${file}...`);
|
|
const sql = readFileSync(join(process.cwd(), file), 'utf-8');
|
|
|
|
// Split SQL into individual statements
|
|
const statements = sql
|
|
.split(';')
|
|
.map(s => s.trim())
|
|
.filter(s => s.length > 0 && !s.startsWith('--'));
|
|
|
|
for (const statement of statements) {
|
|
if (statement.trim()) {
|
|
try {
|
|
await supabase.rpc('exec_sql', { sql: statement + ';' });
|
|
} catch (e) {
|
|
console.log(`⚠️ Statement failed (might already exist): ${statement.substring(0, 50)}...`);
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(`✅ Applied ${file}`);
|
|
} catch (e) {
|
|
console.log(`❌ Failed to apply ${file}:`, e.message);
|
|
}
|
|
}
|
|
|
|
// 3. Verify tables were created
|
|
console.log('\n🔍 Verifying schema...');
|
|
const essentialTables = [
|
|
'profiles', 'campaigns', 'user_products', 'user_services',
|
|
'user_causes', 'loans', 'messages', 'timeline_events'
|
|
];
|
|
|
|
for (const table of essentialTables) {
|
|
try {
|
|
const { error } = await supabase.from(table).select('count').limit(1);
|
|
if (!error) {
|
|
console.log(`✅ ${table} - OK`);
|
|
} else {
|
|
console.log(`❌ ${table} - MISSING`);
|
|
}
|
|
} catch (e) {
|
|
console.log(`❌ ${table} - ERROR`);
|
|
}
|
|
}
|
|
|
|
console.log('\n🎉 Schema application complete!');
|
|
console.log('🔄 Restart your Next.js app to pick up the new schema');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Schema application failed:', error);
|
|
}
|
|
}
|
|
|
|
applyCompleteSchema();
|