paperclipai/paperclip · warning

${label} had drifted migration history; repaired migration j

Error message

${label} had drifted migration history; repaired migration journal entries from existing schema state.

What it means

At startup, ensureMigrations inspects the database; on 'pending-migrations' it first runs reconcilePendingMigrationHistory, which repairs drizzle migration journal entries from the actual schema state when tables already exist (journal lost, partially written, or out of sync). This warning records which journal entries were repaired, then re-inspects and continues if the DB is now up to date.

Source

Thrown at server/src/index.ts:208

      prompt.close();
    }
  }
  
  type EnsureMigrationsOptions = {
    autoApply?: boolean;
  };
  
  async function ensureMigrations(
    connectionString: string,
    label: string,
    opts?: EnsureMigrationsOptions,
  ): Promise<MigrationSummary> {
    const autoApply = opts?.autoApply === true;
    let state = await inspectMigrations(connectionString);
    if (state.status === "needsMigrations" && state.reason === "pending-migrations") {
      const repair = await reconcilePendingMigrationHistory(connectionString);
      if (repair.repairedMigrations.length > 0) {
        logger.warn(
          { repairedMigrations: repair.repairedMigrations },
          `${label} had drifted migration history; repaired migration journal entries from existing schema state.`,
        );
        state = await inspectMigrations(connectionString);
        if (state.status === "upToDate") return "already applied";
      }
    }
    if (state.status === "upToDate") return "already applied";
    if (state.status === "needsMigrations" && state.reason === "no-migration-journal-non-empty-db") {
      logger.warn(
        { tableCount: state.tableCount },
        `${label} has existing tables but no migration journal. Run migrations manually to sync schema.`,
      );
      const apply = autoApply ? true : await promptApplyMigrations(state.pendingMigrations);
      if (!apply) {
        throw new Error(
          `${label} has pending migrations (${formatPendingMigrationSummary(state.pendingMigrations)}). ` +
            "Refusing to start against a stale schema. Run pnpm db:migrate or set PAPERCLIP_MIGRATION_AUTO_APPLY=true.",

View on GitHub (pinned to a7e689b3c3)

Solutions

  1. Usually benign — the repair realigned the journal with the existing schema; verify startup continued to 'already applied'.
  2. If it recurs, diff the schema against `pnpm db:generate` output and ensure exactly one tool applies migrations.
  3. Take a snapshot before restarts for databases with a history of drift.
  4. For DBs with tables but no journal at all, follow the separate 'no migration journal' path (baseline or migrate manually).
Defensive patterns

Strategy: validation

Validate before calling

// Pre-deploy: require a clean migration state against a prod snapshot.
const state = await inspectMigrations(connectionString);
if (state.status === 'needsMigrations') {
  throw new Error(`Migration state needs attention (${state.reason}); run pnpm db:migrate deliberately`);
}

Prevention

When it happens

Trigger: A database whose schema already contains the 'pending' migrations but whose drizzle journal does not record them — restored snapshots with journal drift, migrations applied by another tool, or a partially damaged journal table.

Common situations: Backup/restore pipelines that lose or truncate the journal; DBs touched by manual DDL or external tooling; copying prod to staging; older Paperclip versions that wrote the journal differently.

Related errors


AI-assisted analysis of paperclipai/paperclip@a7e689b3c3 (2026-08-18). Data as JSON: /api/errors/81c3b1d576e481e2. Report an issue: GitHub.