Files
twenty/packages/twenty-server/src/database/commands/base.command.ts
Weiko a16b0d233e add delete view fields without views command (#8728)
## Context
We recently added a command to ensure uniqueness on the viewId column in
the viewField table. This created some issues for some old workspaces
that had viewFields with an empty viewId.
This command should get rid of those and set the column as non-nullable.
Also updating the onDelete action accordingly and set one missing for
FavoriteFolder
2024-11-26 10:40:17 +01:00

56 lines
1.2 KiB
TypeScript

import { Logger } from '@nestjs/common';
import chalk from 'chalk';
import { CommandRunner, Option } from 'nest-commander';
export type BaseCommandOptions = {
workspaceId?: string;
dryRun?: boolean;
verbose?: boolean;
};
export abstract class BaseCommandRunner extends CommandRunner {
protected readonly logger: Logger;
constructor() {
super();
this.logger = new Logger(this.constructor.name);
}
@Option({
flags: '-d, --dry-run',
description: 'Simulate the command without making actual changes',
required: false,
})
parseDryRun(): boolean {
return true;
}
@Option({
flags: '--verbose',
description: 'Verbose output',
})
parseVerbose() {
return true;
}
override async run(
passedParams: string[],
options: BaseCommandOptions,
): Promise<void> {
try {
await this.executeBaseCommand(passedParams, options);
} catch (error) {
this.logger.error(chalk.red(`Command failed`));
throw error;
} finally {
this.logger.log(chalk.blue('Command completed!'));
}
}
protected abstract executeBaseCommand(
passedParams: string[],
options: BaseCommandOptions,
): Promise<void>;
}