{"record":{"id":"06478576e09c6662","repo":"can1357/oh-my-pi","slug":"database-not-found-dbpath","errorCode":null,"errorMessage":"database not found: ${dbPath}","messagePattern":"database not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/mnemopi/src/core/migrations/e6-triplestore-split.ts","lineNumber":159,"sourceCode":"\t}\n\treturn written;\n}\n\nexport function migrate(\n\tdbPathOrOptions: DatabasePath | MigrationOptions,\n\tdryRun = false,\n\tbackup = true,\n\tlogFn: (line: string) => void = console.log,\n): number {\n\tconst options =\n\t\ttypeof dbPathOrOptions === \"string\" ? { dbPath: dbPathOrOptions, dryRun, backup, logFn } : dbPathOrOptions;\n\tconst dbPath = options.dbPath;\n\tconst effectiveDryRun = options.dryRun ?? false;\n\tconst effectiveBackup = options.backup ?? true;\n\tconst effectiveLog = options.logFn ?? console.log;\n\tif (dbPath === \":memory:\" || !existsSync(dbPath)) {\n\t\teffectiveLog(`ERROR: database not found: ${dbPath}`);\n\t\tthrow new Error(`database not found: ${dbPath}`);\n\t}\n\n\tlet db = openDatabase(dbPath);\n\tlet classified: Classification;\n\ttry {\n\t\tclassified = classifyRows(db);\n\t} finally {\n\t\tcloseQuietly(db);\n\t}\n\n\teffectiveLog(`Database: ${dbPath}`);\n\teffectiveLog(`  triples rows (total):        ${classified.total}`);\n\teffectiveLog(`  rows-to-migrate (this run):  ${classified.rows.length}`);\n\tif (classified.rows.length > 0) {\n\t\tconst counts = kindCounts(classified.rows);\n\t\tfor (const kind of Object.keys(counts).sort()) effectiveLog(`    ${kind.padEnd(14, \" \")} ${counts[kind]}`);\n\t}\n\tif (classified.rows.length === 0) {","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/core/migrations/e6-triplestore-split.ts#L141-L177","documentation":"The e6-triplestore-split migration refuses to run when the target SQLite database file does not exist on disk (or is the ':memory:' special path). It logs 'ERROR: database not found: <path>' and throws so a migration never creates a fresh empty database and silently 'migrates' nothing — you must point it at an existing pre-E6 database.","triggerScenarios":"Calling migrate with options.dbPath pointing to a nonexistent file (typo, wrong working directory, relative path resolved differently) or explicitly ':memory:' — checked via existsSync before openDatabase is called.","commonSituations":"Running the migration script from a different cwd than the app that created the DB; pointing at a backup filename that was never created; using ':memory:' expecting the migration to work in-memory; Docker volume not mounted so the DB path is empty.","solutions":["Pass the correct absolute path to the existing mnemopi database via options.dbPath","Run the migration from the same working directory (or use an absolute path) so the relative dbPath resolves","Restore or locate the real database file before migrating; do not let a fresh DB be created","Remove ':memory:' as dbPath — this migration requires an on-disk database"],"exampleFix":"// before\nawait migration.migrate({ dbPath: \":memory:\" });\n// after\nawait migration.migrate({ dbPath: \"/home/me/.hermes/mnemopi/memory.db\" });","handlingStrategy":"validation","validationCode":"import { existsSync } from \"node:fs\";\nimport * as path from \"node:path\";\nfunction assertDbReady(dbPath: string): void {\n  if (dbPath === \":memory:\" || !existsSync(dbPath)) {\n    throw new Error(`migration target DB not found: ${path.resolve(dbPath)}`);\n  }\n}\nassertDbReady(options.dbPath); // call before migration.migrate(...)","typeGuard":"function isExistingDbPath(p: string): p is string {\n  return p !== \":memory:\" && existsSync(p);\n}","tryCatchPattern":"try {\n  await migration.migrate({ dbPath });\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"database not found:\")) {\n    console.error(`Fix dbPath — resolved to ${path.resolve(dbPath)} which does not exist`);\n  } else throw err;\n}","preventionTips":["Always pass absolute dbPath values, never cwd-relative ones","Never use ':memory:' as a migration target","Verify the DB file exists (and is the pre-migration backup) before running e6-triplestore-split","Run migrations from the same working directory/context as the application"],"tags":["migration","sqlite","file-not-found"],"backgroundTag":"database-file-not-found","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}