Skip to content

Commit

Permalink
Catch workspace issues in backfill upgrade commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Weiko authored and mdrazak2001 committed Dec 20, 2024
1 parent f1e38db commit 2ff79d0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ export class RecordPositionBackfillCommand extends ActiveWorkspacesCommandRunner
workspaceIds: string[],
): Promise<void> {
for (const workspaceId of workspaceIds) {
await this.recordPositionBackfillService.backfill(
workspaceId,
options.dryRun ?? false,
);
try {
await this.recordPositionBackfillService.backfill(
workspaceId,
options.dryRun ?? false,
);
} catch (error) {
this.logger.error(
`Error backfilling record position for workspace ${workspaceId}: ${error}`,
);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,53 @@ export class ViewGroupNoValueBackfillCommand extends ActiveWorkspacesCommandRunn
workspaceIds: string[],
): Promise<void> {
for (const workspaceId of workspaceIds) {
const viewRepository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace<ViewWorkspaceEntity>(
workspaceId,
'view',
);
try {
const viewRepository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace<ViewWorkspaceEntity>(
workspaceId,
'view',
);

const viewGroupRepository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace<ViewGroupWorkspaceEntity>(
workspaceId,
'viewGroup',
);
const viewGroupRepository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace<ViewGroupWorkspaceEntity>(
workspaceId,
'viewGroup',
);

const views = await viewRepository.find({
relations: ['viewGroups'],
});
const views = await viewRepository.find({
relations: ['viewGroups'],
});

for (const view of views) {
if (view.viewGroups.length === 0) {
continue;
}
for (const view of views) {
if (view.viewGroups.length === 0) {
continue;
}

// We're assuming for now that all viewGroups belonging to the same view have the same fieldMetadataId
const viewGroup = view.viewGroups?.[0];
const fieldMetadataId = viewGroup?.fieldMetadataId;
// We're assuming for now that all viewGroups belonging to the same view have the same fieldMetadataId
const viewGroup = view.viewGroups?.[0];
const fieldMetadataId = viewGroup?.fieldMetadataId;

if (!fieldMetadataId || !viewGroup) {
continue;
}
if (!fieldMetadataId || !viewGroup) {
continue;
}

const fieldMetadata = await this.fieldMetadataRepository.findOne({
where: { id: viewGroup.fieldMetadataId },
});
const fieldMetadata = await this.fieldMetadataRepository.findOne({
where: { id: viewGroup.fieldMetadataId },
});

if (!fieldMetadata) {
continue;
}
if (!fieldMetadata) {
continue;
}

await this.fieldMetadataRelatedRecordsService.syncNoValueViewGroup(
fieldMetadata,
view,
viewGroupRepository,
await this.fieldMetadataRelatedRecordsService.syncNoValueViewGroup(
fieldMetadata,
view,
viewGroupRepository,
);
}
} catch (error) {
this.logger.error(
`Error backfilling view group no value for workspace ${workspaceId}: ${error}`,
);
}
}
Expand Down

0 comments on commit 2ff79d0

Please sign in to comment.