* Open an existing database
(dbPath: string)
| 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. |
no test coverage detected