From f0383a830e83c7b644e6a03ca647cd0bb32dcbe9 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Fri, 20 Dec 2024 17:30:52 +0100 Subject: [PATCH] Release 0.34.4 --- packages/twenty-emails/package.json | 2 +- packages/twenty-front/package.json | 2 +- packages/twenty-server/package.json | 2 +- .../commands/database-command.module.ts | 2 + ...hone-calling-code-create-column.command.ts | 142 ++++++++++++++++++ .../0-35/0-35-upgrade-version.command.ts | 38 +++++ .../0-35/0-35-upgrade-version.module.ts | 22 +++ packages/twenty-ui/package.json | 2 +- packages/twenty-website/package.json | 2 +- 9 files changed, 209 insertions(+), 5 deletions(-) create mode 100644 packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-phone-calling-code-create-column.command.ts create mode 100644 packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-upgrade-version.command.ts create mode 100644 packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-upgrade-version.module.ts diff --git a/packages/twenty-emails/package.json b/packages/twenty-emails/package.json index 8684bd3cca5c..a5ec15ade6d9 100644 --- a/packages/twenty-emails/package.json +++ b/packages/twenty-emails/package.json @@ -1,6 +1,6 @@ { "name": "twenty-emails", - "version": "0.34.3", + "version": "0.34.4", "description": "", "author": "", "private": true, diff --git a/packages/twenty-front/package.json b/packages/twenty-front/package.json index af21109269ce..ec8497a67875 100644 --- a/packages/twenty-front/package.json +++ b/packages/twenty-front/package.json @@ -1,6 +1,6 @@ { "name": "twenty-front", - "version": "0.34.3", + "version": "0.34.4", "private": true, "type": "module", "scripts": { diff --git a/packages/twenty-server/package.json b/packages/twenty-server/package.json index 0541e4141fd7..b8b514158f6b 100644 --- a/packages/twenty-server/package.json +++ b/packages/twenty-server/package.json @@ -1,6 +1,6 @@ { "name": "twenty-server", - "version": "0.34.3", + "version": "0.34.4", "description": "", "author": "", "private": true, diff --git a/packages/twenty-server/src/database/commands/database-command.module.ts b/packages/twenty-server/src/database/commands/database-command.module.ts index 75bbce194f25..e25e01cdb03c 100644 --- a/packages/twenty-server/src/database/commands/database-command.module.ts +++ b/packages/twenty-server/src/database/commands/database-command.module.ts @@ -10,6 +10,7 @@ import { ConfirmationQuestion } from 'src/database/commands/questions/confirmati import { UpgradeTo0_32CommandModule } from 'src/database/commands/upgrade-version/0-32/0-32-upgrade-version.module'; import { UpgradeTo0_33CommandModule } from 'src/database/commands/upgrade-version/0-33/0-33-upgrade-version.module'; import { UpgradeTo0_34CommandModule } from 'src/database/commands/upgrade-version/0-34/0-34-upgrade-version.module'; +import { UpgradeTo0_35CommandModule } from 'src/database/commands/upgrade-version/0-35/0-35-upgrade-version.module'; import { TypeORMModule } from 'src/database/typeorm/typeorm.module'; import { BillingSubscription } from 'src/engine/core-modules/billing/entities/billing-subscription.entity'; import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity'; @@ -51,6 +52,7 @@ import { WorkspaceSyncMetadataModule } from 'src/engine/workspace-manager/worksp UpgradeTo0_32CommandModule, UpgradeTo0_33CommandModule, UpgradeTo0_34CommandModule, + UpgradeTo0_35CommandModule, FeatureFlagModule, ], providers: [ diff --git a/packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-phone-calling-code-create-column.command.ts b/packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-phone-calling-code-create-column.command.ts new file mode 100644 index 000000000000..950819f2db4a --- /dev/null +++ b/packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-phone-calling-code-create-column.command.ts @@ -0,0 +1,142 @@ +import { InjectRepository } from '@nestjs/typeorm'; + +import chalk from 'chalk'; +import { Command } from 'nest-commander'; +import { Repository } from 'typeorm'; +import { v4 } from 'uuid'; + +import { + ActiveWorkspacesCommandOptions, + ActiveWorkspacesCommandRunner, +} from 'src/database/commands/active-workspaces.command'; +import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity'; +import { + FieldMetadataEntity, + FieldMetadataType, +} from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; +import { WorkspaceMetadataVersionService } from 'src/engine/metadata-modules/workspace-metadata-version/services/workspace-metadata-version.service'; +import { generateMigrationName } from 'src/engine/metadata-modules/workspace-migration/utils/generate-migration-name.util'; +import { + WorkspaceMigrationColumnActionType, + WorkspaceMigrationTableAction, + WorkspaceMigrationTableActionType, +} from 'src/engine/metadata-modules/workspace-migration/workspace-migration.entity'; +import { WorkspaceMigrationFactory } from 'src/engine/metadata-modules/workspace-migration/workspace-migration.factory'; +import { WorkspaceMigrationService } from 'src/engine/metadata-modules/workspace-migration/workspace-migration.service'; +import { computeObjectTargetTable } from 'src/engine/utils/compute-object-target-table.util'; +import { WorkspaceMigrationRunnerService } from 'src/engine/workspace-manager/workspace-migration-runner/workspace-migration-runner.service'; +import { isDefined } from 'src/utils/is-defined'; + +@Command({ + name: 'upgrade-0.35:phone-calling-code-create-column', + description: 'Create the callingCode column', +}) +export class PhoneCallingCodeCreateColumnCommand extends ActiveWorkspacesCommandRunner { + constructor( + @InjectRepository(Workspace, 'core') + protected readonly workspaceRepository: Repository, + @InjectRepository(FieldMetadataEntity, 'metadata') + private readonly fieldMetadataRepository: Repository, + private readonly workspaceMigrationService: WorkspaceMigrationService, + private readonly workspaceMigrationFactory: WorkspaceMigrationFactory, + private readonly workspaceMigrationRunnerService: WorkspaceMigrationRunnerService, + private readonly workspaceMetadataVersionService: WorkspaceMetadataVersionService, + ) { + super(workspaceRepository); + } + + async executeActiveWorkspacesCommand( + _passedParam: string[], + options: ActiveWorkspacesCommandOptions, + workspaceIds: string[], + ): Promise { + this.logger.log( + 'Running command to add calling code and change country code with default one', + ); + + this.logger.verbose(`Part 1 - Workspace`); + let workspaceIterator = 1; + + for (const workspaceId of workspaceIds) { + this.logger.verbose( + `Running command for workspace ${workspaceId} ${workspaceIterator}/${workspaceIds.length}`, + ); + + this.logger.verbose( + `P1 Step 1 - let's find all the fieldsMetadata that have the PHONES type, and extract the objectMetadataId`, + ); + + try { + const phonesFieldMetadata = await this.fieldMetadataRepository.find({ + where: { + workspaceId, + type: FieldMetadataType.PHONES, + }, + relations: ['object'], + }); + + for (const phoneFieldMetadata of phonesFieldMetadata) { + if ( + isDefined(phoneFieldMetadata?.name) && + isDefined(phoneFieldMetadata.object) + ) { + this.logger.verbose( + `P1 Step 1 - Let's find the "nameSingular" of this objectMetadata: ${phoneFieldMetadata.object.nameSingular || 'not found'}`, + ); + + if (!phoneFieldMetadata.object?.nameSingular) continue; + + this.logger.verbose( + `P1 Step 1 - Create migration for field ${phoneFieldMetadata.name}`, + ); + + if (options.dryRun) { + continue; + } + await this.workspaceMigrationService.createCustomMigration( + generateMigrationName( + `create-${phoneFieldMetadata.object.nameSingular}PrimaryPhoneCallingCode-for-field-${phoneFieldMetadata.name}`, + ), + workspaceId, + [ + { + name: computeObjectTargetTable(phoneFieldMetadata.object), + action: WorkspaceMigrationTableActionType.ALTER, + columns: this.workspaceMigrationFactory.createColumnActions( + WorkspaceMigrationColumnActionType.CREATE, + { + id: v4(), + type: FieldMetadataType.TEXT, + name: `${phoneFieldMetadata.name}PrimaryPhoneCallingCode`, + label: `${phoneFieldMetadata.name}PrimaryPhoneCallingCode`, + objectMetadataId: phoneFieldMetadata.object.id, + workspaceId: workspaceId, + isNullable: true, + defaultValue: "''", + } satisfies Partial, + ), + } satisfies WorkspaceMigrationTableAction, + ], + ); + } + } + + this.logger.verbose( + `P1 Step 1 - RUN migration to create callingCodes for ${workspaceId.slice(0, 5)}`, + ); + await this.workspaceMigrationRunnerService.executeMigrationFromPendingMigrations( + workspaceId, + ); + + await this.workspaceMetadataVersionService.incrementMetadataVersion( + workspaceId, + ); + } catch (error) { + this.logger.log(`Error in workspace ${workspaceId} : ${error}`); + } + workspaceIterator++; + } + + this.logger.log(chalk.green(`Command completed!`)); + } +} diff --git a/packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-upgrade-version.command.ts b/packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-upgrade-version.command.ts new file mode 100644 index 000000000000..a4133b6cc28b --- /dev/null +++ b/packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-upgrade-version.command.ts @@ -0,0 +1,38 @@ +import { InjectRepository } from '@nestjs/typeorm'; + +import { Command } from 'nest-commander'; +import { Repository } from 'typeorm'; + +import { ActiveWorkspacesCommandRunner } from 'src/database/commands/active-workspaces.command'; +import { PhoneCallingCodeCreateColumnCommand } from 'src/database/commands/upgrade-version/0-35/0-35-phone-calling-code-create-column.command'; +import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity'; + +interface UpdateTo0_35CommandOptions { + workspaceId?: string; +} + +@Command({ + name: 'upgrade-0.35', + description: 'Upgrade to 0.35', +}) +export class UpgradeTo0_35Command extends ActiveWorkspacesCommandRunner { + constructor( + @InjectRepository(Workspace, 'core') + protected readonly workspaceRepository: Repository, + private readonly phoneCallingCodeCreateColumnCommand: PhoneCallingCodeCreateColumnCommand, + ) { + super(workspaceRepository); + } + + async executeActiveWorkspacesCommand( + passedParam: string[], + options: UpdateTo0_35CommandOptions, + workspaceIds: string[], + ): Promise { + await this.phoneCallingCodeCreateColumnCommand.executeActiveWorkspacesCommand( + passedParam, + options, + workspaceIds, + ); + } +} diff --git a/packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-upgrade-version.module.ts b/packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-upgrade-version.module.ts new file mode 100644 index 000000000000..171addd381bd --- /dev/null +++ b/packages/twenty-server/src/database/commands/upgrade-version/0-35/0-35-upgrade-version.module.ts @@ -0,0 +1,22 @@ +import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; + +import { PhoneCallingCodeCreateColumnCommand } from 'src/database/commands/upgrade-version/0-35/0-35-phone-calling-code-create-column.command'; +import { UpgradeTo0_35Command } from 'src/database/commands/upgrade-version/0-35/0-35-upgrade-version.command'; +import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity'; +import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity'; +import { WorkspaceMetadataVersionModule } from 'src/engine/metadata-modules/workspace-metadata-version/workspace-metadata-version.module'; +import { WorkspaceMigrationModule } from 'src/engine/metadata-modules/workspace-migration/workspace-migration.module'; +import { WorkspaceMigrationRunnerModule } from 'src/engine/workspace-manager/workspace-migration-runner/workspace-migration-runner.module'; + +@Module({ + imports: [ + TypeOrmModule.forFeature([Workspace], 'core'), + TypeOrmModule.forFeature([FieldMetadataEntity], 'metadata'), + WorkspaceMigrationRunnerModule, + WorkspaceMetadataVersionModule, + WorkspaceMigrationModule, + ], + providers: [UpgradeTo0_35Command, PhoneCallingCodeCreateColumnCommand], +}) +export class UpgradeTo0_35CommandModule {} diff --git a/packages/twenty-ui/package.json b/packages/twenty-ui/package.json index d4b1006491b2..d99f7367f92e 100644 --- a/packages/twenty-ui/package.json +++ b/packages/twenty-ui/package.json @@ -1,6 +1,6 @@ { "name": "twenty-ui", - "version": "0.34.3", + "version": "0.34.4", "type": "module", "main": "./src/index.ts", "exports": { diff --git a/packages/twenty-website/package.json b/packages/twenty-website/package.json index 6e067608d4e9..3eb329a18856 100644 --- a/packages/twenty-website/package.json +++ b/packages/twenty-website/package.json @@ -1,6 +1,6 @@ { "name": "twenty-website", - "version": "0.34.3", + "version": "0.34.4", "private": true, "scripts": { "nx": "NX_DEFAULT_PROJECT=twenty-website node ../../node_modules/nx/bin/nx.js",