{"record":{"id":"6af7a3c441fe46d6","repo":"thedotmack/claude-mem","slug":"schema-v46-missing-target-table-target-colum","errorCode":null,"errorMessage":"schema v46: missing ${target.table}.${target.column}","messagePattern":"schema v46: missing (.+?)\\.(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/services/sqlite/SessionStore.ts","lineNumber":707,"sourceCode":"    const columnInfo = (table: string, column: string): TableColumnInfo | undefined =>\n      (this.db.query(`PRAGMA table_info(${table})`).all() as TableColumnInfo[])\n        .find(info => info.name === column);\n    const isText = (info: TableColumnInfo | undefined): boolean =>\n      info?.type.trim().toUpperCase() === 'TEXT';\n    const applied = this.db.prepare(\n      'SELECT version FROM schema_versions WHERE version = ?'\n    ).get(46) as SchemaVersion | undefined;\n\n    if (applied && targets.every(target => isText(columnInfo(target.table, target.column)))) {\n      return;\n    }\n\n    const tx = this.db.transaction(() => {\n      for (const target of targets) {\n        const columns = this.db.query(`PRAGMA table_info(${target.table})`).all() as TableColumnInfo[];\n        const source = columns.find(info => info.name === target.column);\n        if (!source) {\n          throw new Error(`schema v46: missing ${target.table}.${target.column}`);\n        }\n\n        for (const raw of streamRows(this.db.query(`\n          SELECT CAST(id AS TEXT) AS row_id,\n                 typeof(${target.column}) AS storage_type,\n                 CAST(${target.column} AS TEXT) AS revision\n          FROM ${target.table}\n        `))) {\n          const row = raw as { row_id: string; storage_type: string; revision: string | null };\n          if (row.storage_type === 'real') {\n            throw new Error(\n              `schema v46: ${target.table}.${target.column} row ${row.row_id} is REAL and unrecoverably rounded`\n            );\n          }\n          if (row.storage_type !== 'integer' && row.storage_type !== 'text') {\n            throw new Error(\n              `schema v46: ${target.table}.${target.column} row ${row.row_id} has unsupported ${row.storage_type} storage`\n            );","sourceCodeStart":689,"sourceCodeEnd":725,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/sqlite/SessionStore.ts#L689-L725","documentation":"During the schema-v46 migration (ensureSyncRevisionTextAffinity, run from the SessionStore constructor), PRAGMA table_info does not list the expected sync-revision column on the target table. This is an internal invariant: the migration assumes the column exists, and its absence means the schema is in an unexpected state, so startup aborts.","triggerScenarios":"Opening a database whose schema is older/newer than expected such that sync_rev (or the other v46 target column) is missing from the target table when the v46 affinity migration runs.","commonSituations":"Restoring a partially migrated database file from backup; downgrading the app after a future schema version dropped the column; a corrupted or hand-edited database.","solutions":["Restore a database backup taken before the failed migration","Check which schema_versions rows exist and run the migration chain from a matching app version","Recreate the database by deleting ~/.claude-mem/claude-mem.db if data is disposable","Report the DB state (PRAGMA table_info output) as a bug if the column should exist"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check target column exists before opening the store\nconst cols = db.query(\"PRAGMA table_info(sdk_sessions)\").all();\nif (!cols.some(c => c.name === 'sync_rev')) console.error('DB missing sync_rev; restore backup');","typeGuard":null,"tryCatchPattern":"try { store = new SessionStore(dbPath); } catch (e) {\n  if (String(e.message).startsWith('schema v46: missing')) {\n    restoreBackupOrRebuild(dbPath); // fatal: cannot continue with this DB\n  } else throw e;\n}","preventionTips":["Back up the database before upgrading app versions","Never downgrade the app to a version older than the DB schema","Don't hand-edit or subset a live database file"],"tags":["schema","migration","sqlite","startup"],"backgroundTag":"schema-validation-failed","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}