{"record":{"id":"ff5f363ed88785f8","repo":"paperclipai/paperclip","slug":"migrations-are-still-pending-after-migration-histo","errorCode":null,"errorMessage":"Migrations are still pending after migration-history reconciliation; run inspectMigrations for details.","messagePattern":"Migrations are still pending after migration-history reconciliation; run inspectMigrations for details\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/db/src/client.ts","lineNumber":851,"sourceCode":"  }\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\");\n      const folderMillis = folderMillisByFile.get(migrationFile) ?? Date.now();\n      const existingByHash = columnNames.has(\"hash\")\n        ? await sql.unsafe<{ created_at: string | number | null }[]>(\n            `SELECT created_at FROM ${qualifiedTable} WHERE hash = ${quoteLiteral(hash)} ORDER BY created_at DESC LIMIT 1`,\n          )\n        : [];\n      const existingByName = columnNames.has(\"name\")\n        ? await sql.unsafe<{ created_at: string | number | null }[]>(\n            `SELECT created_at FROM ${qualifiedTable} WHERE name = ${quoteLiteral(migrationFile)} ORDER BY created_at DESC LIMIT 1`,\n          )\n        : [];\n      if (existingByHash.length > 0 || existingByName.length > 0) {\n        if (columnNames.has(\"created_at\")) {\n          const existingHashCreatedAt = Number(existingByHash[0]?.created_at ?? -1);\n          if (existingByHash.length > 0 && Number.isFinite(existingHashCreatedAt) && existingHashCreatedAt < folderMillis) {","sourceCodeStart":833,"sourceCodeEnd":869,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/packages/db/src/client.ts#L833-L869","documentation":"Terminal failure of the runtime migration path: after running the reconciliation pass against the migration history, the database still reports the pending-migrations state, meaning reconciliation could not account for the discrepancy; the message points at inspectMigrations for diagnosis.","triggerScenarios":"Thrown at packages/db/src/client.ts:771 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run inspectMigrations to see pending migrations and reconcile history manually."],"exampleFix":null,"handlingStrategy":"retry","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-14T00:17:10.932Z"}