-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-fts.js
More file actions
97 lines (84 loc) · 2.85 KB
/
debug-fts.js
File metadata and controls
97 lines (84 loc) · 2.85 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
#!/usr/bin/env node
import Database from 'better-sqlite3';
import path from 'path';
import os from 'os';
const dbPath = path.join(os.homedir(), '.claude', 'claude-history-enhanced.db');
const db = new Database(dbPath);
console.log('🔍 Debugging FTS Tables\n');
// Check what tables exist
console.log('📊 All tables:');
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all();
tables.forEach(t => console.log(` • ${t.name}`));
// Check FTS tables specifically
console.log('\n📝 FTS Tables:');
const ftsTables = tables.filter(t => t.name.includes('fts'));
ftsTables.forEach(t => {
console.log(`\n Table: ${t.name}`);
// Get schema
const schemaQuery = db.prepare(`SELECT sql FROM sqlite_master WHERE name = ?`).get(t.name);
console.log(` Schema: ${schemaQuery?.sql}`);
// Count rows
try {
const count = db.prepare(`SELECT COUNT(*) as count FROM ${t.name}`).get();
console.log(` Rows: ${count.count}`);
} catch (e) {
console.log(` Rows: Error - ${e.message}`);
}
});
// Check key_interactions table
console.log('\n📋 key_interactions table:');
const kiCount = db.prepare('SELECT COUNT(*) as count FROM key_interactions').get();
console.log(` Total rows: ${kiCount.count}`);
// Sample a few rows
const kiSample = db.prepare('SELECT id, conversation_id FROM key_interactions LIMIT 3').all();
console.log(' Sample rows:');
kiSample.forEach(row => {
console.log(` ID: ${row.id}, Conv ID: ${row.conversation_id}`);
});
// Test basic FTS query directly
console.log('\n🧪 Testing FTS queries:');
// Test 1: Direct FTS query
console.log('\nTest 1: Direct query on interactions_fts');
try {
const ftsTest = db.prepare(`
SELECT interaction_id
FROM interactions_fts
WHERE interactions_fts MATCH 'docker'
LIMIT 3
`).all();
console.log(` ✅ Success! Found ${ftsTest.length} results`);
} catch (e) {
console.log(` ❌ Error: ${e.message}`);
}
// Test 2: Direct query on errors_fts
console.log('\nTest 2: Direct query on errors_fts');
try {
const errorFtsTest = db.prepare(`
SELECT conversation_id
FROM errors_fts
WHERE errors_fts MATCH 'error'
LIMIT 3
`).all();
console.log(` ✅ Success! Found ${errorFtsTest.length} results`);
} catch (e) {
console.log(` ❌ Error: ${e.message}`);
}
// Test 3: Join query
console.log('\nTest 3: Join with key_interactions');
try {
const joinTest = db.prepare(`
SELECT DISTINCT ki.conversation_id
FROM key_interactions ki
WHERE ki.id IN (
SELECT interaction_id
FROM interactions_fts
WHERE interactions_fts MATCH 'docker'
)
LIMIT 3
`).all();
console.log(` ✅ Success! Found ${joinTest.length} results`);
} catch (e) {
console.log(` ❌ Error: ${e.message}`);
}
db.close();
console.log('\n✅ Debug complete!');