From 1a763263c9705208e78df3fd6358758902a28c70 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Fri, 22 Mar 2024 18:20:38 +0100 Subject: [PATCH] Add workspaceId option on standard-id migration script --- .../commands/add-standard-id.command.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/add-standard-id.command.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/add-standard-id.command.ts index 5e7cb3151e19..9c2d577e0f97 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/add-standard-id.command.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/add-standard-id.command.ts @@ -1,7 +1,7 @@ import { Logger } from '@nestjs/common'; import { InjectDataSource } from '@nestjs/typeorm'; -import { Command, CommandRunner } from 'nest-commander'; +import { Command, CommandRunner, Option } from 'nest-commander'; import { DataSource } from 'typeorm'; import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; @@ -12,6 +12,10 @@ import { computeStandardObject } from 'src/engine/workspace-manager/workspace-sy import { StandardFieldFactory } from 'src/engine/workspace-manager/workspace-sync-metadata/factories/standard-field.factory'; import { CustomObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/custom-objects/custom.object-metadata'; +interface RunCommandOptions { + workspaceId?: string; +} + @Command({ name: 'workspace:add-standard-id', description: 'Add standard id to all metadata objects and fields', @@ -28,8 +32,9 @@ export class AddStandardIdCommand extends CommandRunner { super(); } - async run(): Promise { + async run(_passedParam: string[], options: RunCommandOptions): Promise { const queryRunner = this.metadataDataSource.createQueryRunner(); + const workspaceId = options.workspaceId; await queryRunner.connect(); await queryRunner.startTransaction(); @@ -81,6 +86,7 @@ export class AddStandardIdCommand extends CommandRunner { await objectMetadataRepository.find({ where: { fields: { isCustom: false }, + workspaceId: workspaceId, }, relations: ['fields'], }); @@ -88,6 +94,7 @@ export class AddStandardIdCommand extends CommandRunner { originalObjectMetadataCollection.filter( (metadata) => metadata.isCustom, ); + const standardObjectMetadataMap = new Map( standardObjectMetadataCollection.map((metadata) => [ metadata.nameSingular, @@ -152,4 +159,13 @@ export class AddStandardIdCommand extends CommandRunner { await queryRunner.release(); } } + + @Option({ + flags: '-w, --workspace-id [workspace_id]', + description: 'workspace id', + required: false, + }) + parseWorkspaceId(value: string): string { + return value; + } }