Skip to content

Commit

Permalink
Improve add field to view script to handle errors (#6232)
Browse files Browse the repository at this point in the history
Adding logs and catching errors to continue not to block the script
execution if the command fails for one workspace
  • Loading branch information
ijreilly authored Jul 12, 2024
1 parent 4350279 commit ad5d090
Showing 1 changed file with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,24 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
}

for (const workspaceId of workspaceIds) {
const viewFieldRepository =
await this.twentyORMManager.getRepositoryForWorkspace(
workspaceId,
ViewFieldWorkspaceEntity,
);

const dataSourceMetadatas =
await this.dataSourceService.getDataSourcesMetadataFromWorkspaceId(
workspaceId,
);

for (const dataSourceMetadata of dataSourceMetadatas) {
const workspaceDataSource =
await this.typeORMService.connectToDataSource(dataSourceMetadata);

if (workspaceDataSource) {
try {
this.logger.log(`Running command for workspace ${workspaceId}`);
try {
const viewFieldRepository =
await this.twentyORMManager.getRepositoryForWorkspace(
workspaceId,
ViewFieldWorkspaceEntity,
);

const dataSourceMetadatas =
await this.dataSourceService.getDataSourcesMetadataFromWorkspaceId(
workspaceId,
);

for (const dataSourceMetadata of dataSourceMetadatas) {
const workspaceDataSource =
await this.typeORMService.connectToDataSource(dataSourceMetadata);

if (workspaceDataSource) {
const newAddressField = await this.fieldMetadataRepository.findBy({
workspaceId,
standardId: newFieldStandardId,
Expand Down Expand Up @@ -156,22 +157,24 @@ export class AddNewAddressFieldToViewsWithDeprecatedAddressFieldCommand extends
`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);
await this.workspaceCacheVersionService.incrementVersion(workspaceId);

this.logger.log(
chalk.green(`Running command on workspace ${workspaceId} done`),
);
}
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;
}

this.logger.log(chalk.green(`Command completed!`));
this.logger.log(chalk.green(`Command completed!`));
}
}
}

0 comments on commit ad5d090

Please sign in to comment.