From 2ff79d03693b2ca51666b935b681ae93b7dd1668 Mon Sep 17 00:00:00 2001 From: Weiko Date: Fri, 20 Dec 2024 12:11:05 +0100 Subject: [PATCH] Catch workspace issues in backfill upgrade commands --- .../0-40-record-position-backfill.command.ts | 14 ++-- ...40-view-group-no-value-backfill.command.ts | 72 ++++++++++--------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/packages/twenty-server/src/database/commands/upgrade-version/0-40/0-40-record-position-backfill.command.ts b/packages/twenty-server/src/database/commands/upgrade-version/0-40/0-40-record-position-backfill.command.ts index 53c26618d3df..f0804e873077 100644 --- a/packages/twenty-server/src/database/commands/upgrade-version/0-40/0-40-record-position-backfill.command.ts +++ b/packages/twenty-server/src/database/commands/upgrade-version/0-40/0-40-record-position-backfill.command.ts @@ -27,10 +27,16 @@ export class RecordPositionBackfillCommand extends ActiveWorkspacesCommandRunner workspaceIds: string[], ): Promise { 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}`, + ); + } } } } diff --git a/packages/twenty-server/src/database/commands/upgrade-version/0-40/0-40-view-group-no-value-backfill.command.ts b/packages/twenty-server/src/database/commands/upgrade-version/0-40/0-40-view-group-no-value-backfill.command.ts index ed66287ff574..63662563dd67 100644 --- a/packages/twenty-server/src/database/commands/upgrade-version/0-40/0-40-view-group-no-value-backfill.command.ts +++ b/packages/twenty-server/src/database/commands/upgrade-version/0-40/0-40-view-group-no-value-backfill.command.ts @@ -34,47 +34,53 @@ export class ViewGroupNoValueBackfillCommand extends ActiveWorkspacesCommandRunn workspaceIds: string[], ): Promise { for (const workspaceId of workspaceIds) { - const viewRepository = - await this.twentyORMGlobalManager.getRepositoryForWorkspace( - workspaceId, - 'view', - ); + try { + const viewRepository = + await this.twentyORMGlobalManager.getRepositoryForWorkspace( + workspaceId, + 'view', + ); - const viewGroupRepository = - await this.twentyORMGlobalManager.getRepositoryForWorkspace( - workspaceId, - 'viewGroup', - ); + const viewGroupRepository = + await this.twentyORMGlobalManager.getRepositoryForWorkspace( + 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}`, ); } }