Improve add field to view script to handle errors (#6232)
Adding logs and catching errors to continue not to block the script execution if the command fails for one workspace
This commit is contained in:
@ -80,23 +80,24 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const workspaceId of workspaceIds) {
|
for (const workspaceId of workspaceIds) {
|
||||||
const viewFieldRepository =
|
this.logger.log(`Running command for workspace ${workspaceId}`);
|
||||||
await this.twentyORMManager.getRepositoryForWorkspace(
|
try {
|
||||||
workspaceId,
|
const viewFieldRepository =
|
||||||
ViewFieldWorkspaceEntity,
|
await this.twentyORMManager.getRepositoryForWorkspace(
|
||||||
);
|
workspaceId,
|
||||||
|
ViewFieldWorkspaceEntity,
|
||||||
|
);
|
||||||
|
|
||||||
const dataSourceMetadatas =
|
const dataSourceMetadatas =
|
||||||
await this.dataSourceService.getDataSourcesMetadataFromWorkspaceId(
|
await this.dataSourceService.getDataSourcesMetadataFromWorkspaceId(
|
||||||
workspaceId,
|
workspaceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const dataSourceMetadata of dataSourceMetadatas) {
|
for (const dataSourceMetadata of dataSourceMetadatas) {
|
||||||
const workspaceDataSource =
|
const workspaceDataSource =
|
||||||
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
||||||
|
|
||||||
if (workspaceDataSource) {
|
if (workspaceDataSource) {
|
||||||
try {
|
|
||||||
const newAddressField = await this.fieldMetadataRepository.findBy({
|
const newAddressField = await this.fieldMetadataRepository.findBy({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
standardId: newFieldStandardId,
|
standardId: newFieldStandardId,
|
||||||
@ -156,22 +157,24 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
|
|||||||
`New address field successfully added to view ${viewId} for workspace ${workspaceId}`,
|
`New address field successfully added to view ${viewId} for workspace ${workspaceId}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(`Running command on workspace ${workspaceId} failed`),
|
|
||||||
);
|
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.workspaceCacheVersionService.incrementVersion(workspaceId);
|
||||||
|
|
||||||
|
this.logger.log(
|
||||||
|
chalk.green(`Running command on workspace ${workspaceId} done`),
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.log(
|
||||||
|
chalk.red(
|
||||||
|
`Running command on workspace ${workspaceId} failed with error: ${error}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.workspaceCacheVersionService.incrementVersion(workspaceId);
|
this.logger.log(chalk.green(`Command completed!`));
|
||||||
|
|
||||||
this.logger.log(
|
|
||||||
chalk.green(`Running command on workspace ${workspaceId} done`),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.log(chalk.green(`Command completed!`));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user