Skip to content

Commit

Permalink
Release 0.34.4
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesBochet committed Dec 20, 2024
1 parent 10f6335 commit f0383a8
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/twenty-emails/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twenty-emails",
"version": "0.34.3",
"version": "0.34.4",
"description": "",
"author": "",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-front/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twenty-front",
"version": "0.34.3",
"version": "0.34.4",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twenty-server",
"version": "0.34.3",
"version": "0.34.4",
"description": "",
"author": "",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,6 +52,7 @@ import { WorkspaceSyncMetadataModule } from 'src/engine/workspace-manager/worksp
UpgradeTo0_32CommandModule,
UpgradeTo0_33CommandModule,
UpgradeTo0_34CommandModule,
UpgradeTo0_35CommandModule,
FeatureFlagModule,
],
providers: [
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Workspace>,
@InjectRepository(FieldMetadataEntity, 'metadata')
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
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<void> {
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<FieldMetadataEntity>,
),
} 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!`));
}
}
Original file line number Diff line number Diff line change
@@ -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<Workspace>,
private readonly phoneCallingCodeCreateColumnCommand: PhoneCallingCodeCreateColumnCommand,
) {
super(workspaceRepository);
}

async executeActiveWorkspacesCommand(
passedParam: string[],
options: UpdateTo0_35CommandOptions,
workspaceIds: string[],
): Promise<void> {
await this.phoneCallingCodeCreateColumnCommand.executeActiveWorkspacesCommand(
passedParam,
options,
workspaceIds,
);
}
}
Original file line number Diff line number Diff line change
@@ -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 {}
2 changes: 1 addition & 1 deletion packages/twenty-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twenty-ui",
"version": "0.34.3",
"version": "0.34.4",
"type": "module",
"main": "./src/index.ts",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/twenty-website/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit f0383a8

Please sign in to comment.