MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / open

Method open

src/db/index.ts:98–121  ·  view source on GitHub ↗

* Open an existing database

(dbPath: string)

Source from the content-addressed store, hash-verified

96 * Open an existing database
97 */
98 static open(dbPath: string): DatabaseConnection {
99 if (!fs.existsSync(dbPath)) {
100 throw new Error(`Database not found: ${dbPath}`);
101 }
102
103 const { db, backend } = createDatabase(dbPath);
104
105 configureConnection(db);
106
107 // Check and run migrations if needed
108 const conn = new DatabaseConnection(db, dbPath, backend);
109 const currentVersion = getCurrentVersion(db);
110
111 if (currentVersion < CURRENT_SCHEMA_VERSION) {
112 runMigrations(db, currentVersion);
113 }
114
115 // Self-heal a bulk-load window that never closed (crash between
116 // beginBulkNodeLoad and endBulkNodeLoad): the FTS triggers are missing and
117 // nodes_fts is stale. Rebuild + recreate so search stays in sync.
118 conn.healBulkNodeLoad();
119
120 return conn;
121 }
122
123 /**
124 * FTS maintenance triggers dropped/recreated around a bulk load.

Callers 2

doInitializeMethod · 0.45
mainFunction · 0.45

Calls 5

healBulkNodeLoadMethod · 0.95
createDatabaseFunction · 0.90
getCurrentVersionFunction · 0.90
runMigrationsFunction · 0.90
configureConnectionFunction · 0.85

Tested by

no test coverage detected