toeverything/AFFiNE · warning · Error

Migration has not been executed.

Error message

Migration ${name} has not been executed.

What it means

Thrown by RevertCommand when the migration name is valid but no row exists in the dataMigration table for it — the migration was never executed on this database (or was already reverted, which deletes the record).

Solutions

  1. Check the dataMigration table contents to confirm which migrations are actually recorded as executed.
  2. If you need to revert its effects, run the migration first ('data run <name>'), then revert.
  3. Treat this as a no-op in automation: the end state (migration not applied) is already true.
Defensive patterns

Strategy: validation

Validate before calling

// Check the applied record before reverting
const record = await prisma.dataMigration.findFirst({ where: { name } });
if (!record) {
  console.log(`Migration ${name} is not applied — nothing to revert.`);
  process.exit(0);
}

Try / catch

try {
  await revertCommand.execute(name);
} catch (e) {
  if (e instanceof Error && e.message.includes('has not been executed')) {
    // desired end state already holds
    process.exit(0);
  }
}

Prevention

When it happens

Trigger: Running 'data revert <name>' against a fresh database where the migration never ran, or reverting the same migration a second time.

Common situations: Reverting on a newly provisioned environment; double-execution of the revert script; the record was deleted by a previous successful revert.

Related errors


AI-assisted analysis of toeverything/AFFiNE@591f874dad (2026-08-18). Data as JSON: /api/errors/c51cb2d723ce8c93. Report an issue: GitHub.

Appendix: source

Thrown at packages/backend/server/src/data/commands/run.ts:198

    const migration = migrations.find(m => m.name === name);

    if (!migration) {
      this.logger.error('Available migration names:');
      migrations.forEach(m => {
        this.logger.error(`  - ${m.name}`);
      });
      throw new Error(`Unknown migration name: ${name}.`);
    }

    const record = await this.db.dataMigration.findFirst({
      where: {
        name: migration.name,
      },
    });

    if (!record) {
      throw new Error(`Migration ${name} has not been executed.`);
    }

    try {
      this.logger.log(`Reverting ${name}...`);
      await migration.down(this.db, this.injector);
      this.logger.log('Done reverting');
    } catch (e) {
      this.logger.error(`Failed to revert data migration ${name}`, e);
    }

    await this.db.dataMigration.delete({
      where: {
        id: record.id,
      },
    });
  }
}

View on GitHub (pinned to 591f874dad)