Skip to content

Commit

Permalink
Add workspaceId option on standard-id migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesBochet committed Mar 22, 2024
1 parent 5665656 commit 1a76326
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand All @@ -28,8 +32,9 @@ export class AddStandardIdCommand extends CommandRunner {
super();
}

async run(): Promise<void> {
async run(_passedParam: string[], options: RunCommandOptions): Promise<void> {
const queryRunner = this.metadataDataSource.createQueryRunner();
const workspaceId = options.workspaceId;

await queryRunner.connect();
await queryRunner.startTransaction();
Expand Down Expand Up @@ -81,13 +86,15 @@ export class AddStandardIdCommand extends CommandRunner {
await objectMetadataRepository.find({
where: {
fields: { isCustom: false },
workspaceId: workspaceId,
},
relations: ['fields'],
});
const customObjectMetadataCollection =
originalObjectMetadataCollection.filter(
(metadata) => metadata.isCustom,
);

const standardObjectMetadataMap = new Map(
standardObjectMetadataCollection.map((metadata) => [
metadata.nameSingular,
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 1a76326

Please sign in to comment.