* Recreate the FTS sync triggers from schema.sql — extracted from the file * rather than duplicated here so the DDL cannot drift from the schema. * (Re-execing the whole schema is not an option: it contains data INSERTs * that are not idempotent, e.g. schema_versions.)
()
| 337 | * that are not idempotent, e.g. schema_versions.) |
| 338 | */ |
| 339 | private recreateFtsTriggers(): void { |
| 340 | const schemaPath = path.join(__dirname, 'schema.sql'); |
| 341 | const schema = fs.readFileSync(schemaPath, 'utf-8'); |
| 342 | const triggerDdls = schema.match( |
| 343 | /CREATE TRIGGER IF NOT EXISTS nodes_a[idu]\b[\s\S]*?END;/g |
| 344 | ); |
| 345 | if (!triggerDdls || triggerDdls.length !== DatabaseConnection.FTS_TRIGGER_NAMES.length) { |
| 346 | throw new Error( |
| 347 | `schema.sql: expected ${DatabaseConnection.FTS_TRIGGER_NAMES.length} nodes FTS triggers, found ${triggerDdls?.length ?? 0}` |
| 348 | ); |
| 349 | } |
| 350 | for (const ddl of triggerDdls) { |
| 351 | this.db.exec(ddl); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Get the underlying database instance |
no test coverage detected