{"record":{"id":"41305bbc50dfaa0b","repo":"paperclipai/paperclip","slug":"database-has-tables-but-no-migration-journal-auto","errorCode":null,"errorMessage":"Database has tables but no migration journal; automatic migration is unsafe. Initialize migration history manually.","messagePattern":"Database has tables but no migration journal; automatic migration is unsafe\\. Initialize migration history manually\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/db/src/client.ts","lineNumber":836,"sourceCode":"\n  return availableMigrations.slice(0, Math.max(0, rows.length));\n}\n\nexport type MigrationHistoryReconcileResult = {\n  repairedMigrations: string[];\n  remainingMigrations: string[];\n};\n\nexport async function reconcilePendingMigrationHistory(\n  url: string,\n): Promise<MigrationHistoryReconcileResult> {\n  const state = await inspectMigrations(url);\n  if (state.status !== \"needsMigrations\" || state.reason !== \"pending-migrations\") {\n    return { repairedMigrations: [], remainingMigrations: [] };\n  }\n\n  const sql = createUtilitySql(url);\n  const repairedMigrations: string[] = [];\n\n  try {\n    const journalEntries = await listJournalMigrationEntries();\n    const folderMillisByFile = new Map(journalEntries.map((entry) => [entry.fileName, entry.folderMillis]));\n    const migrationTableSchema = await discoverMigrationTableSchema(sql);\n    if (!migrationTableSchema) {\n      return { repairedMigrations, remainingMigrations: state.pendingMigrations };\n    }\n\n    const columnNames = await getMigrationTableColumnNames(sql, migrationTableSchema);\n    const qualifiedTable = `${quoteIdentifier(migrationTableSchema)}.${quoteIdentifier(DRIZZLE_MIGRATIONS_TABLE)}`;\n\n    for (const migrationFile of state.pendingMigrations) {\n      const migrationContent = await readMigrationFileContent(migrationFile);\n      const alreadyApplied = await migrationContentAlreadyApplied(sql, migrationContent);\n      if (!alreadyApplied) break;\n\n      const hash = createHash(\"sha256\").update(migrationContent).digest(\"hex\");","sourceCodeStart":818,"sourceCodeEnd":854,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/packages/db/src/client.ts#L818-L854","documentation":"Safety refusal during automatic migration: the target database already contains tables but has no drizzle migration journal, so the migrator cannot distinguish 'already migrated by other means' from 'diverged schema' and refuses to guess, requiring manual migration-history initialization.","triggerScenarios":"Thrown at packages/db/src/client.ts:756 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Initialize migration history manually (baseline the existing schema) before enabling automatic migration."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}