-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-database-fixed.ts
More file actions
106 lines (84 loc) · 3.29 KB
/
Copy pathsetup-database-fixed.ts
File metadata and controls
106 lines (84 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Fixed Setup Script - Provides clear instructions for setting up Supabase
import { createClient } from '@supabase/supabase-js';
import { readFile } from 'fs/promises';
import dotenv from 'dotenv';
dotenv.config();
const SUPABASE_URL = process.env.SUPABASE_URL!;
const SUPABASE_ANON_KEY = process.env.SUPABASE_ANON_KEY!;
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
async function checkTables() {
const tables = [
'videos', 'channel_stats', 'minting_events', 'thumbnails', 'oracle_state',
'playlists', 'playlist_images', 'nft_mints', 'holders', 'airdrops'
];
let existingTables = 0;
let missingTables = 0;
console.log('\n🔍 Checking existing tables...\n');
for (const table of tables) {
try {
const { error, count } = await supabase
.from(table)
.select('*', { count: 'exact', head: true });
if (error) {
console.log(` ❌ ${table}`);
missingTables++;
} else {
console.log(` ✅ ${table} (${count || 0} rows)`);
existingTables++;
}
} catch (e: any) {
console.log(` ❌ ${table}`);
missingTables++;
}
}
return { existingTables, missingTables, total: tables.length };
}
async function main() {
console.log('\n' + '═'.repeat(70));
console.log('🗄️ SUPABASE DATABASE SETUP');
console.log('═'.repeat(70));
console.log(`\n📍 URL: ${SUPABASE_URL}`);
console.log(`🔗 URL: ${SUPABASE_URL}`);
// Check current state
const { existingTables, missingTables, total } = await checkTables();
console.log(`\n📊 Status: ${existingTables}/${total} tables exist`);
if (missingTables === 0) {
console.log('\n' + '═'.repeat(70));
console.log('✅ ALL TABLES EXIST - Setup Complete!');
console.log('═'.repeat(70));
console.log('\n💡 Next steps:');
console.log(' - npm run validate # Validate setup');
console.log(' - npm start # Start the oracle\n');
return;
}
// Need to create tables
console.log('\n' + '═'.repeat(70));
console.log('⚠️ TABLES NEED TO BE CREATED');
console.log('═'.repeat(70));
console.log('\n📝 INSTRUCTIONS:\n');
console.log('1. Open your Supabase SQL Editor:');
console.log(` 🔗 Open your Supabase project's SQL Editor\n`);
console.log('2. Copy the entire contents of: complete-schema.sql\n');
console.log('3. Paste into the SQL Editor and click "Run"\n');
console.log('4. Run this script again to verify:\n');
console.log(' npx tsx setup-database-fixed.ts\n');
// Show the SQL file location
console.log('═'.repeat(70));
console.log('📄 SQL FILE LOCATION');
console.log('═'.repeat(70));
try {
const sql = await readFile('complete-schema.sql', 'utf-8');
const lineCount = sql.split('\n').length;
const charCount = sql.length;
console.log(`\n✅ Found: complete-schema.sql`);
console.log(` 📏 ${lineCount} lines, ${charCount} characters`);
console.log(` 📦 Creates all ${total} tables + indexes + triggers\n`);
} catch (error) {
console.log('\n❌ Could not find complete-schema.sql');
console.log(' Make sure you are in the project root directory\n');
}
console.log('═'.repeat(70));
console.log('⏰ ESTIMATED TIME: 5 minutes');
console.log('═'.repeat(70) + '\n');
}
main().catch(console.error);