{"record":{"id":"60bb4ac3fede6a6c","repo":"toeverything/AFFiNE","slug":"a-migration-name-is-required","errorCode":null,"errorMessage":"A migration name is required","messagePattern":"A migration name is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/backend/server/src/data/commands/run.ts","lineNumber":176,"sourceCode":"      data: {\n        finishedAt: new Date(),\n      },\n    });\n  }\n}\n\n@Injectable()\nexport class RevertCommand {\n  logger = new Logger(RevertCommand.name);\n\n  constructor(\n    private readonly db: PrismaClient,\n    private readonly injector: ModuleRef\n  ) {}\n\n  async execute(name?: string): Promise<void> {\n    if (!name) {\n      throw new Error('A migration name is required');\n    }\n\n    const migrations = collectMigrations();\n\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      },","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/591f874dad30887a80143a061a44bd3ca7ee3299/packages/backend/server/src/data/commands/run.ts#L158-L194","documentation":"Thrown by RevertCommand.execute(name?) — the 'data revert' CLI command — when no migration name argument was provided. Reverting requires knowing exactly which migration to roll back, so an undefined name is a usage error.","triggerScenarios":"Running 'node cli.js data revert' with no argument.","commonSituations":"Operator assumes revert defaults to the last applied migration (it does not); shell quoting swallowed the argument; automation script parameter left empty.","solutions":["Pass the exact migration name to revert: 'node cli.js data revert <migrationName>'.","If you don't know the name, query the dataMigration table (SELECT name FROM \"DataMigration\") for applied migrations.","Quote the name in the shell to preserve any special characters."],"exampleFix":"// before\n$ node cli.js data revert\n// after\n$ node cli.js data revert add-notification-guessed-1698900000","handlingStrategy":"validation","validationCode":"// Guard the CLI wrapper\nif (typeof argv._[1] !== 'string' || !argv._[1]) {\n  console.error('Usage: data revert <migration-name>');\n  process.exit(1);\n}\nawait revertCommand.execute(argv._[1]);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Script the revert command with a mandatory-name assertion and print applied names from the dataMigration table."],"tags":["cli","migration","revert","argument"],"backgroundTag":"missing-cli-argument","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"}