fix: workspace health (#3916)
* fix: workspace health applying migrations multiple times * fix: remove log * fix: use logger
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
import { Logger } from '@nestjs/common';
|
||||||
|
|
||||||
import { Command, CommandRunner, Option } from 'nest-commander';
|
import { Command, CommandRunner, Option } from 'nest-commander';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
|
|
||||||
@ -20,6 +22,7 @@ interface WorkspaceHealthCommandOptions {
|
|||||||
description: 'Check health of the given workspace.',
|
description: 'Check health of the given workspace.',
|
||||||
})
|
})
|
||||||
export class WorkspaceHealthCommand extends CommandRunner {
|
export class WorkspaceHealthCommand extends CommandRunner {
|
||||||
|
private readonly logger = new Logger(WorkspaceHealthCommand.name);
|
||||||
private readonly commandLogger = new CommandLogger(
|
private readonly commandLogger = new CommandLogger(
|
||||||
WorkspaceHealthCommand.name,
|
WorkspaceHealthCommand.name,
|
||||||
);
|
);
|
||||||
@ -40,21 +43,23 @@ export class WorkspaceHealthCommand extends CommandRunner {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (issues.length === 0) {
|
if (issues.length === 0) {
|
||||||
console.log(chalk.green('Workspace is healthy'));
|
this.logger.log(chalk.green('Workspace is healthy'));
|
||||||
} else {
|
} else {
|
||||||
console.log(chalk.red('Workspace is not healthy'));
|
this.logger.log(
|
||||||
|
chalk.red(`Workspace is not healthy, found ${issues.length} issues`),
|
||||||
|
);
|
||||||
|
|
||||||
if (options.verbose) {
|
if (options.verbose) {
|
||||||
console.group(chalk.red('Issues'));
|
await this.commandLogger.writeLog(
|
||||||
issues.forEach((issue) => {
|
`workspace-health-issues-${options.workspaceId}`,
|
||||||
console.log(chalk.yellow(JSON.stringify(issue, null, 2)));
|
issues,
|
||||||
});
|
);
|
||||||
console.groupEnd();
|
this.logger.log(chalk.yellow('Issues written to log'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.fix) {
|
if (options.fix) {
|
||||||
console.log(chalk.yellow('Fixing issues'));
|
this.logger.log(chalk.yellow('Fixing issues'));
|
||||||
|
|
||||||
const workspaceMigrations = await this.workspaceHealthService.fixIssues(
|
const workspaceMigrations = await this.workspaceHealthService.fixIssues(
|
||||||
options.workspaceId,
|
options.workspaceId,
|
||||||
@ -71,7 +76,7 @@ export class WorkspaceHealthCommand extends CommandRunner {
|
|||||||
workspaceMigrations,
|
workspaceMigrations,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
this.logger.log(
|
||||||
chalk.green(
|
chalk.green(
|
||||||
`Fixed ${workspaceMigrations.length}/${issues.length} issues`,
|
`Fixed ${workspaceMigrations.length}/${issues.length} issues`,
|
||||||
),
|
),
|
||||||
|
|||||||
@ -28,24 +28,19 @@ export class WorkspaceFixDefaultValueService {
|
|||||||
issues: WorkspaceHealthDefaultValueIssue[],
|
issues: WorkspaceHealthDefaultValueIssue[],
|
||||||
): Promise<Partial<WorkspaceMigrationEntity>[]> {
|
): Promise<Partial<WorkspaceMigrationEntity>[]> {
|
||||||
const workspaceMigrations: Partial<WorkspaceMigrationEntity>[] = [];
|
const workspaceMigrations: Partial<WorkspaceMigrationEntity>[] = [];
|
||||||
|
const defaultValueIssues = issues.filter(
|
||||||
|
(issue) =>
|
||||||
|
issue.type === WorkspaceHealthIssueType.COLUMN_DEFAULT_VALUE_CONFLICT,
|
||||||
|
) as WorkspaceHealthColumnIssue<WorkspaceHealthIssueType.COLUMN_DEFAULT_VALUE_CONFLICT>[];
|
||||||
|
|
||||||
for (const issue of issues) {
|
if (defaultValueIssues.length > 0) {
|
||||||
switch (issue.type) {
|
const columnDefaultValueWorkspaceMigrations =
|
||||||
case WorkspaceHealthIssueType.COLUMN_DEFAULT_VALUE_CONFLICT: {
|
await this.fixColumnDefaultValueIssues(
|
||||||
const columnNullabilityWorkspaceMigrations =
|
objectMetadataCollection,
|
||||||
await this.fixColumnDefaultValueIssues(
|
defaultValueIssues,
|
||||||
objectMetadataCollection,
|
);
|
||||||
issues.filter(
|
|
||||||
(issue) =>
|
|
||||||
issue.type ===
|
|
||||||
WorkspaceHealthIssueType.COLUMN_DEFAULT_VALUE_CONFLICT,
|
|
||||||
) as WorkspaceHealthColumnIssue<WorkspaceHealthIssueType.COLUMN_DEFAULT_VALUE_CONFLICT>[],
|
|
||||||
);
|
|
||||||
|
|
||||||
workspaceMigrations.push(...columnNullabilityWorkspaceMigrations);
|
workspaceMigrations.push(...columnDefaultValueWorkspaceMigrations);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return workspaceMigrations;
|
return workspaceMigrations;
|
||||||
|
|||||||
@ -27,24 +27,19 @@ export class WorkspaceFixNullableService {
|
|||||||
issues: WorkspaceHealthNullableIssue[],
|
issues: WorkspaceHealthNullableIssue[],
|
||||||
): Promise<Partial<WorkspaceMigrationEntity>[]> {
|
): Promise<Partial<WorkspaceMigrationEntity>[]> {
|
||||||
const workspaceMigrations: Partial<WorkspaceMigrationEntity>[] = [];
|
const workspaceMigrations: Partial<WorkspaceMigrationEntity>[] = [];
|
||||||
|
const nullabilityIssues = issues.filter(
|
||||||
|
(issue) =>
|
||||||
|
issue.type === WorkspaceHealthIssueType.COLUMN_NULLABILITY_CONFLICT,
|
||||||
|
) as WorkspaceHealthColumnIssue<WorkspaceHealthIssueType.COLUMN_NULLABILITY_CONFLICT>[];
|
||||||
|
|
||||||
for (const issue of issues) {
|
if (nullabilityIssues.length > 0) {
|
||||||
switch (issue.type) {
|
const columnNullabilityWorkspaceMigrations =
|
||||||
case WorkspaceHealthIssueType.COLUMN_NULLABILITY_CONFLICT: {
|
await this.fixColumnNullabilityIssues(
|
||||||
const columnNullabilityWorkspaceMigrations =
|
objectMetadataCollection,
|
||||||
await this.fixColumnNullabilityIssues(
|
nullabilityIssues,
|
||||||
objectMetadataCollection,
|
);
|
||||||
issues.filter(
|
|
||||||
(issue) =>
|
|
||||||
issue.type ===
|
|
||||||
WorkspaceHealthIssueType.COLUMN_NULLABILITY_CONFLICT,
|
|
||||||
) as WorkspaceHealthColumnIssue<WorkspaceHealthIssueType.COLUMN_NULLABILITY_CONFLICT>[],
|
|
||||||
);
|
|
||||||
|
|
||||||
workspaceMigrations.push(...columnNullabilityWorkspaceMigrations);
|
workspaceMigrations.push(...columnNullabilityWorkspaceMigrations);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return workspaceMigrations;
|
return workspaceMigrations;
|
||||||
|
|||||||
@ -30,24 +30,19 @@ export class WorkspaceFixTypeService {
|
|||||||
issues: WorkspaceHealthTypeIssue[],
|
issues: WorkspaceHealthTypeIssue[],
|
||||||
): Promise<Partial<WorkspaceMigrationEntity>[]> {
|
): Promise<Partial<WorkspaceMigrationEntity>[]> {
|
||||||
const workspaceMigrations: Partial<WorkspaceMigrationEntity>[] = [];
|
const workspaceMigrations: Partial<WorkspaceMigrationEntity>[] = [];
|
||||||
|
const columnTypeIssues = issues.filter(
|
||||||
|
(issue) =>
|
||||||
|
issue.type === WorkspaceHealthIssueType.COLUMN_DATA_TYPE_CONFLICT,
|
||||||
|
) as WorkspaceHealthColumnIssue<WorkspaceHealthIssueType.COLUMN_DATA_TYPE_CONFLICT>[];
|
||||||
|
|
||||||
for (const issue of issues) {
|
if (columnTypeIssues.length > 0) {
|
||||||
switch (issue.type) {
|
const columnNullabilityWorkspaceMigrations =
|
||||||
case WorkspaceHealthIssueType.COLUMN_DATA_TYPE_CONFLICT: {
|
await this.fixColumnTypeIssues(
|
||||||
const columnNullabilityWorkspaceMigrations =
|
objectMetadataCollection,
|
||||||
await this.fixColumnTypeIssues(
|
columnTypeIssues,
|
||||||
objectMetadataCollection,
|
);
|
||||||
issues.filter(
|
|
||||||
(issue) =>
|
|
||||||
issue.type ===
|
|
||||||
WorkspaceHealthIssueType.COLUMN_DATA_TYPE_CONFLICT,
|
|
||||||
) as WorkspaceHealthColumnIssue<WorkspaceHealthIssueType.COLUMN_DATA_TYPE_CONFLICT>[],
|
|
||||||
);
|
|
||||||
|
|
||||||
workspaceMigrations.push(...columnNullabilityWorkspaceMigrations);
|
workspaceMigrations.push(...columnNullabilityWorkspaceMigrations);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return workspaceMigrations;
|
return workspaceMigrations;
|
||||||
|
|||||||
Reference in New Issue
Block a user