-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspect_tables.js
More file actions
76 lines (61 loc) · 2.08 KB
/
inspect_tables.js
File metadata and controls
76 lines (61 loc) · 2.08 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
const { execSync } = require('child_process');
// SpacetimeDB Table Inspector
// This script uses the spacetime CLI to check all tables
console.log('🔍 SpacetimeDB Table Inspector');
console.log('=====================================');
const MODULE_NAME = 'hophacks-chat';
const tables = [
'AiReplies',
'GameResult',
'GameRooms',
'Leaderboard',
'Messages',
'RoomPlayers',
'RoomTemplate',
'Users'
];
function runQuery(query, description) {
console.log(`\n🔎 ${description}`);
console.log(`Query: ${query}`);
console.log('Result:');
try {
const result = execSync(`spacetime sql ${MODULE_NAME} "${query}"`, {
encoding: 'utf-8',
timeout: 5000
});
console.log(result || '(No data returned)');
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
}
// Check if spacetime CLI is available
try {
execSync('spacetime --version', { stdio: 'pipe' });
console.log('✅ SpacetimeDB CLI found');
} catch (error) {
console.log('❌ SpacetimeDB CLI not found. Please install it first.');
console.log(' Visit: https://spacetimedb.com/docs/install');
process.exit(1);
}
console.log(`\n📦 Checking module: ${MODULE_NAME}`);
// Check each table
tables.forEach(table => {
console.log(`\n=== ${table.toUpperCase()} TABLE ===`);
// Get table structure/schema
runQuery(`DESCRIBE ${table}`, `${table} Schema`);
// Count rows
runQuery(`SELECT COUNT(*) as count FROM ${table}`, `${table} Row Count`);
// Get sample data (first 3 rows)
runQuery(`SELECT * FROM ${table} LIMIT 3`, `${table} Sample Data`);
});
// Summary
console.log('\n=== DATABASE SUMMARY ===');
const summaryQuery = tables.map(table =>
`(SELECT COUNT(*) FROM ${table}) as ${table.toLowerCase()}_count`
).join(', ');
runQuery(`SELECT ${summaryQuery}`, 'Complete Row Counts');
// Recent activity
console.log('\n=== RECENT ACTIVITY ===');
runQuery('SELECT * FROM Messages ORDER BY timestamp DESC LIMIT 5', 'Latest Messages');
runQuery('SELECT * FROM Leaderboard ORDER BY score DESC LIMIT 5', 'Top Leaderboard');
console.log('\n✅ Table inspection complete!');