{"record":{"id":"c51cb2d723ce8c93","repo":"toeverything/AFFiNE","slug":"migration-name-has-not-been-executed","errorCode":null,"errorMessage":"Migration ${name} has not been executed.","messagePattern":"Migration (.+?) has not been executed\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/backend/server/src/data/commands/run.ts","lineNumber":198,"sourceCode":"\n    const migration = migrations.find(m => m.name === name);\n\n    if (!migration) {\n      this.logger.error('Available migration names:');\n      migrations.forEach(m => {\n        this.logger.error(`  - ${m.name}`);\n      });\n      throw new Error(`Unknown migration name: ${name}.`);\n    }\n\n    const record = await this.db.dataMigration.findFirst({\n      where: {\n        name: migration.name,\n      },\n    });\n\n    if (!record) {\n      throw new Error(`Migration ${name} has not been executed.`);\n    }\n\n    try {\n      this.logger.log(`Reverting ${name}...`);\n      await migration.down(this.db, this.injector);\n      this.logger.log('Done reverting');\n    } catch (e) {\n      this.logger.error(`Failed to revert data migration ${name}`, e);\n    }\n\n    await this.db.dataMigration.delete({\n      where: {\n        id: record.id,\n      },\n    });\n  }\n}\n","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/591f874dad30887a80143a061a44bd3ca7ee3299/packages/backend/server/src/data/commands/run.ts#L180-L216","documentation":"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).","triggerScenarios":"Running 'data revert <name>' against a fresh database where the migration never ran, or reverting the same migration a second time.","commonSituations":"Reverting on a newly provisioned environment; double-execution of the revert script; the record was deleted by a previous successful revert.","solutions":["Check the dataMigration table contents to confirm which migrations are actually recorded as executed.","If you need to revert its effects, run the migration first ('data run <name>'), then revert.","Treat this as a no-op in automation: the end state (migration not applied) is already true."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Check the applied record before reverting\nconst record = await prisma.dataMigration.findFirst({ where: { name } });\nif (!record) {\n  console.log(`Migration ${name} is not applied — nothing to revert.`);\n  process.exit(0);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await revertCommand.execute(name);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('has not been executed')) {\n    // desired end state already holds\n    process.exit(0);\n  }\n}","preventionTips":["Query the dataMigration table to list actually-applied migrations before scripting reverts.","Make revert automation idempotent by treating 'not executed' as success."],"tags":["cli","migration","revert","state-mismatch"],"backgroundTag":"migration-not-applied","analyzedSha":"591f874dad30887a80143a061a44bd3ca7ee3299","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}