Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve add field to view script to handle errors #6232

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!`));
}
}
}
Loading