fix: stop os startup from rewriting nodes fts

This commit is contained in:
“BeeRad”
2026-04-11 21:54:21 +10:00
parent 1de5290d7a
commit 6570e844ab
+4 -9
View File
@@ -1073,21 +1073,16 @@ class SQLiteClient {
} catch {} } catch {}
} }
// Recreate nodes_fts to index title + source + description // Only create nodes_fts when it does not exist yet.
// Do not rewrite existing FTS tables on startup in the OS app.
try { try {
const ftsCheck = this.db.prepare("SELECT sql FROM sqlite_master WHERE name='nodes_fts'").get() as { sql?: string } | undefined; const ftsCheck = this.db.prepare("SELECT sql FROM sqlite_master WHERE name='nodes_fts'").get() as { sql?: string } | undefined;
const needsRebuild = !ftsCheck?.sql || !ftsCheck.sql.includes('source') || ftsCheck.sql.includes('notes') || ftsCheck.sql.includes('content'); if (!ftsCheck?.sql) {
if (needsRebuild) {
this.db.exec('DROP TABLE IF EXISTS nodes_fts;');
this.db.exec("CREATE VIRTUAL TABLE nodes_fts USING fts5(title, source, description, content='nodes', content_rowid='id');"); this.db.exec("CREATE VIRTUAL TABLE nodes_fts USING fts5(title, source, description, content='nodes', content_rowid='id');");
this.db.exec("INSERT INTO nodes_fts(nodes_fts) VALUES('rebuild');"); this.db.exec("INSERT INTO nodes_fts(nodes_fts) VALUES('rebuild');");
} }
} catch (ftsErr) { } catch (ftsErr) {
if (this.isSqliteCorruptError(ftsErr)) { console.warn('Failed to initialize nodes_fts:', ftsErr);
this.disableNodesFts('existing nodes_fts is corrupt and could not be rebuilt', ftsErr);
} else {
console.warn('Failed to rebuild nodes_fts:', ftsErr);
}
} }
} catch (schemaErr) { } catch (schemaErr) {
console.warn('Final schema pass migration error:', schemaErr); console.warn('Final schema pass migration error:', schemaErr);