{"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":138,"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":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/packages/backend/server/src/data/commands/run.ts#L120-L156","documentation":"Thrown by `RevertCommand.execute` when the `name` argument is falsy — the revert CLI was invoked without specifying which migration to revert. A plain `Error` (no error code); revert is a single-migration operation and cannot run without a target.","triggerScenarios":"Running the revert command with no argument, an empty string, or an unset env var. E.g. `revert` alone, or `revert $MIGRATION` with `MIGRATION` empty.","commonSituations":"CI step or shell script that forgets to pass the migration name; env var for the name unset; a wrapper that consumes the argument by mistake; operator running the command interactively without reading usage.","solutions":["Pass the migration name as the argument: `revert 1766000000000-add-indexes`.","In scripts, guard `if [ -z \"$NAME\" ]; then echo 'usage: revert <name>'; exit 1; fi` before calling.","If the name comes from an env var, default or validate it before invoking.","List available names first (`RunCommand`/`RevertCommand` prints them when an unknown name is given)."],"exampleFix":"// before\nawait revertCommand.execute();\n\n// after\nconst name = process.argv[2];\nif (!name) {\n  console.error('Usage: revert <migration-name>');\n  process.exit(1);\n}\nawait revertCommand.execute(name);","handlingStrategy":"validation","validationCode":"const name = process.argv[2];\nif (!name) {\n  console.error('Usage: revert <migration-name>');\n  process.exit(1);\n}\nawait revertCommand.execute(name);","typeGuard":"function hasMigrationName(name) {\n  return typeof name === 'string' && name.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always pass the migration name to the revert command.","Validate the env var / arg before invoking.","Print usage and exit early in wrapper scripts when the name is missing."],"tags":["cli","migration","validation","nestjs"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}