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

Method open

src/db/index.ts:127–154  ·  view source on GitHub ↗

* Open an existing database

(dbPath: string)

Source from the content-addressed store, hash-verified

125 * Open an existing database
126 */
127 static open(dbPath: string): DatabaseConnection {
128 if (!fs.existsSync(dbPath)) {
129 throw new Error(`Database not found: ${dbPath}`);
130 }
131
132 const { db, backend } = createDatabase(dbPath);
133
134 configureConnection(db);
135
136 // Check and run migrations if needed
137 const conn = new DatabaseConnection(db, dbPath, backend);
138 const currentVersion = getCurrentVersion(db);
139
140 if (currentVersion < CURRENT_SCHEMA_VERSION) {
141 runMigrations(db, currentVersion);
142 }
143
144 // Self-heal a bulk-load window that never closed (crash between
145 // beginBulkNodeLoad and endBulkNodeLoad): the FTS triggers are missing and
146 // nodes_fts is stale. Rebuild + recreate so search stays in sync.
147 conn.healBulkNodeLoad();
148
149 // Self-heal a killed session's leftover oversized WAL (#1431) — one
150 // statSync when healthy, off-thread checkpoint+truncate when not.
151 void conn.healOversizedWal();
152
153 return conn;
154 }
155
156 /**
157 * FTS maintenance triggers dropped/recreated around a bulk load.

Callers 2

doInitializeMethod · 0.45
mainFunction · 0.45

Calls 6

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

Tested by

no test coverage detected