{"record":{"id":"bac8da290782d59f","repo":"paperclipai/paperclip","slug":"database-for-configpath-is-not-up-to-date-pen","errorCode":null,"errorMessage":"Database for ${configPath} is not up to date.${pending} Run `pnpm db:migrate` (or start Paperclip once) before using worktree merge history.","messagePattern":"Database for (.+?) is not up to date\\.(.+?) Run `pnpm db:migrate` \\(or start Paperclip once\\) before using worktree merge history\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"cli/src/commands/worktree.ts","lineNumber":2278,"sourceCode":"  }\n  const envEntries = readPaperclipEnvEntries(resolvePaperclipEnvFile(configPath));\n  let embeddedHandle: EmbeddedPostgresHandle | null = null;\n\n  try {\n    if (config.database.mode === \"embedded-postgres\") {\n      embeddedHandle = await ensureEmbeddedPostgres(\n        config.database.embeddedPostgresDataDir,\n        config.database.embeddedPostgresPort,\n      );\n    }\n    const connectionString = resolveSourceConnectionString(config, envEntries, embeddedHandle?.port);\n    const migrationState = await inspectMigrations(connectionString);\n    if (migrationState.status !== \"upToDate\") {\n      const pending =\n        migrationState.reason === \"pending-migrations\"\n          ? ` Pending migrations: ${migrationState.pendingMigrations.join(\", \")}.`\n          : \"\";\n      throw new Error(\n        `Database for ${configPath} is not up to date.${pending} Run \\`pnpm db:migrate\\` (or start Paperclip once) before using worktree merge history.`,\n      );\n    }\n    const db = createDb(connectionString) as ClosableDb;\n    return {\n      db,\n      stop: async () => {\n        await closeDb(db);\n        if (embeddedHandle?.startedByThisProcess) {\n          await embeddedHandle.stop();\n        }\n      },\n    };\n  } catch (error) {\n    if (embeddedHandle?.startedByThisProcess) {\n      await embeddedHandle.stop().catch(() => undefined);\n    }\n    throw error;","sourceCodeStart":2260,"sourceCodeEnd":2296,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/worktree.ts#L2260-L2296","documentation":"Thrown by openConfiguredDb after inspectMigrations() reports the database is not 'upToDate'. Before merge-history reads/writes data, every involved DB must match the latest schema. When reason is 'pending-migrations' the message lists the pending migration names. This guards against merging into a partially-migrated database which would silently drop or mis-shape data.","triggerScenarios":"Running merge-history against a worktree or source DB whose migrations have not been applied (fresh clone, never started); schema was updated in packages/db but `pnpm db:generate`/migrate was not run in this instance; an embedded-postgres data dir from an older schema version.","commonSituations":"Pulled latest main with new migrations but didn't restart Paperclip (which auto-migrates); worktree seeded from a source that was itself behind; embedded PGlite/embedded-postgres data dir out of sync after a schema change.","solutions":["Apply migrations in the failing instance: run `pnpm db:migrate`, or simply start Paperclip once (`pnpm dev`) so auto-migration runs.","Re-seed the worktree from an up-to-date source so its DB matches the current schema.","For an embedded-postgres instance with a stale data dir, reset it (`rm -rf data/pglite` or the embedded dir) and restart to rebuild.","Re-run merge-history after all listed pending migrations are applied."],"exampleFix":"// before: pending migrations block merge-history\n// after\ncd /path/to/instance && pnpm db:migrate   # or: pnpm dev (auto-migrates then stop)\npaperclipai worktree:merge-history","handlingStrategy":"validation","validationCode":"const state = await inspectMigrations(connectionString);\nif (state.status !== \"upToDate\") {\n  throw new Error(`DB not migrated; run pnpm db:migrate. Pending: ${state.pendingMigrations?.join(\", \")}`);\n}","typeGuard":"async function dbUpToDate(conn: string): Promise<boolean> {\n  return (await inspectMigrations(conn)).status === \"upToDate\";\n}","tryCatchPattern":"try { await openConfiguredDb(configPath); }\ncatch (err) {\n  if (/not up to date/.test(String((err as Error).message))) {\n    await runMigrations(configPath); // pnpm db:migrate equivalent\n    await openConfiguredDb(configPath);\n  } else throw err;\n}","preventionTips":["Start Paperclip once (`pnpm dev`) after pulling schema changes so auto-migration runs.","Run `pnpm db:migrate` in each instance before merge-history.","Reset stale embedded DB data dirs and re-seed from an up-to-date source."],"tags":["worktree","database","migration","merge"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}