{"record":{"id":"bd89408cf46a9bf9","repo":"thedotmack/claude-mem","slug":"schema-v46-unexpected-temporary-column-target-t","errorCode":null,"errorMessage":"schema v46: unexpected temporary column ${target.table}.${target.temporary}","messagePattern":"schema v46: unexpected temporary column (.+?)\\.(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/services/sqlite/SessionStore.ts","lineNumber":738,"sourceCode":"            );\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            );\n          }\n          try {\n            assertCanonicalDecimal(row.revision, { positive: true });\n          } catch {\n            throw new Error(\n              `schema v46: ${target.table}.${target.column} row ${row.row_id} is not a positive canonical uint64 revision`\n            );\n          }\n        }\n\n        if (isText(source)) continue;\n        if (columns.some(info => info.name === target.temporary)) {\n          throw new Error(`schema v46: unexpected temporary column ${target.table}.${target.temporary}`);\n        }\n\n        this.db.run(\n          `ALTER TABLE ${target.table} ADD COLUMN ${target.temporary} TEXT NOT NULL DEFAULT '1'`\n        );\n        this.db.run(\n          `UPDATE ${target.table} SET ${target.temporary} = CAST(${target.column} AS TEXT)`\n        );\n        const mismatch = this.db.prepare(`\n          SELECT CAST(id AS TEXT) AS row_id\n          FROM ${target.table}\n          WHERE ${target.temporary} <> CAST(${target.column} AS TEXT)\n          LIMIT 1\n        `).get() as { row_id: string } | undefined;\n        if (mismatch) {\n          throw new Error(\n            `schema v46: failed to copy ${target.table}.${target.column} row ${mismatch.row_id} exactly`\n          );","sourceCodeStart":720,"sourceCodeEnd":756,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/sqlite/SessionStore.ts#L720-L756","documentation":"Before the v46 migration adds its temporary TEXT column, it verifies the temporary column does not already exist. If it does, a previous migration attempt left the table half-migrated (or was interrupted mid-transaction), and continuing could corrupt data, so it throws.","triggerScenarios":"ensureSyncRevisionTextAffinity finds target.temporary (the shadow column added before copy/drop/rename) already present in PRAGMA table_info for the target table.","commonSituations":"A crashed/killed process left a partially applied migration (SQLite DDL is transactional here, but a foreign/older copy of the DB may contain leftovers); restoring a DB dump taken mid-migration.","solutions":["Restore a database backup from before the interrupted migration","Inspect the table: PRAGMA table_info(<table>) and drop leftover temp columns only if their data is redundant","Delete and rebuild the database if the data is expendable","Report as a bug if it reproduces on a healthy DB"],"exampleFix":"-- inspect leftover migration state\nPRAGMA table_info(sdk_sessions);\n-- if safe, let migration restart from a clean pre-v46 backup instead of hand-editing","handlingStrategy":"try-catch","validationCode":"const cols = db.query('PRAGMA table_info(sdk_sessions)').all();\nif (cols.some(c => String(c.name).startsWith('__tmp') || c.name.includes('_tmp_'))) {\n  console.error('Leftover migration temp column; restore backup');\n}","typeGuard":null,"tryCatchPattern":"try { store = new SessionStore(dbPath); } catch (e) {\n  if (String(e.message).includes('unexpected temporary column')) {\n    restoreBackup(dbPath); // do NOT hand-drop the temp column blindly\n  } else throw e;\n}","preventionTips":["Don't kill the process during startup migrations","Never restore a DB dump taken mid-migration","Take backups so interrupted migrations can be rolled back cleanly"],"tags":["schema","migration","sqlite"],"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"}