{"record":{"id":"fcdda35ea2d18761","repo":"paperclipai/paperclip","slug":"migration-journal-is-not-current-migrationstate","errorCode":null,"errorMessage":"Migration journal is not current (${migrationState.pendingMigrations.length} pending migration(s)).","messagePattern":"Migration journal is not current \\((.+?) pending migration\\(s\\)\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/worktree.ts","lineNumber":1482,"sourceCode":"\nexport function resolveWorktreeSeedMigrationRevision(\n  migrationState: Awaited<ReturnType<typeof inspectMigrations>>,\n  requirement: \"sourcePrefix\" | \"upToDate\",\n): string {\n  const expectedAppliedPrefix = migrationState.availableMigrations.slice(\n    0,\n    migrationState.appliedMigrations.length,\n  );\n  const appliedMigrationNames = new Set(migrationState.appliedMigrations);\n  if (\n    appliedMigrationNames.size !== expectedAppliedPrefix.length ||\n    expectedAppliedPrefix.some((migration) => !appliedMigrationNames.has(migration))\n  ) {\n    throw new Error(\"Migration journal is not a prefix of this Paperclip checkout's migration journal.\");\n  }\n\n  if (requirement === \"upToDate\" && migrationState.status !== \"upToDate\") {\n    throw new Error(\n      `Migration journal is not current (${migrationState.pendingMigrations.length} pending migration(s)).`,\n    );\n  }\n\n  const migrationRevision = expectedAppliedPrefix.at(-1);\n  if (!migrationRevision) {\n    throw new Error(\"Migration journal has no applied revision.\");\n  }\n  return migrationRevision;\n}\n\n/**\n * Markerless worktrees predate the versioned seed manifest. Adopt one only\n * after proving that its configured database already has a compatible\n * migration journal and the core Paperclip tables. The physical PG_VERSION\n * check prevents this read-only probe from initializing a missing embedded\n * database and then mistaking that empty cluster for legacy evidence.\n */","sourceCodeStart":1464,"sourceCodeEnd":1500,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/cli/src/commands/worktree.ts#L1464-L1500","documentation":"Second rule of resolveWorktreeSeedMigrationRevision(): with requirement 'upToDate', migrationState.status must be 'upToDate' — zero pending migrations. Seed paths that snapshot or adopt a database require its journal to be fully migrated so the cloned copy is current. The message reports how many migrations are still pending.","triggerScenarios":"resolveWorktreeSeedMigrationRevision(state, 'upToDate') when the source or target database has pending migrations — e.g. the checkout gained new drizzle migrations but the database was never migrated (service not restarted, migrations generated but not applied).","commonSituations":"Pulling new code with fresh migrations without restarting the source service; running db:generate without applying; using an old source worktree as seed origin after the main checkout moved forward.","solutions":["Bring the source database fully up to date (start the Paperclip service or run the migrate step) until inspectMigrations reports upToDate, then retry the seed","Update or re-seed the source instance so its schema matches its checkout","If the source cannot be migrated, pass an explicit source config whose database is current"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const state = await inspectMigrations(/* source connection */);\nif (state.status !== 'upToDate') {\n  await applyPendingMigrations(state.pendingMigrations); // or start the source service first\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bring the source database fully up to date before seeding worktrees from it","Restart the source service after pulling changes that add migrations"],"tags":["migrations","worktree","seed","drizzle","database"],"backgroundTag":"pending-database-migrations","analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-21T17:58:32.592Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}