toeverything/AFFiNE · error · Error
A migration name is required
Error message
A migration name is required
What it means
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.
Source
Thrown at packages/backend/server/src/data/commands/run.ts:138
data: {
finishedAt: new Date(),
},
});
}
}
@Injectable()
export class RevertCommand {
logger = new Logger(RevertCommand.name);
constructor(
private readonly db: PrismaClient,
private readonly injector: ModuleRef
) {}
async execute(name?: string): Promise<void> {
if (!name) {
throw new Error('A migration name is required');
}
const migrations = collectMigrations();
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,
},View on GitHub (pinned to 26c515e050)
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).
Example fix
// before
await revertCommand.execute();
// after
const name = process.argv[2];
if (!name) {
console.error('Usage: revert <migration-name>');
process.exit(1);
}
await revertCommand.execute(name); Defensive patterns
Strategy: validation
Validate before calling
const name = process.argv[2];
if (!name) {
console.error('Usage: revert <migration-name>');
process.exit(1);
}
await revertCommand.execute(name); Type guard
function hasMigrationName(name) {
return typeof name === 'string' && name.length > 0;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- A config file path is required
- invalid_app_config_input
- Invalid migration name: ${migration.name}
- Unknown migration name: ${name}.
- password_required
AI-assisted analysis of toeverything/AFFiNE@26c515e050 (2026-08-12).
Data as JSON: /api/errors/60bb4ac3fede6a6c.
Report an issue: GitHub.