diff --git a/packages/twenty-emails/package.json b/packages/twenty-emails/package.json index 8a34cfd244ea..597d23f2cfda 100644 --- a/packages/twenty-emails/package.json +++ b/packages/twenty-emails/package.json @@ -1,6 +1,6 @@ { "name": "twenty-emails", - "version": "0.22.0", + "version": "0.23.0", "description": "", "author": "", "private": true, diff --git a/packages/twenty-front/package.json b/packages/twenty-front/package.json index 8ff1595fab09..a659a0056907 100644 --- a/packages/twenty-front/package.json +++ b/packages/twenty-front/package.json @@ -1,6 +1,6 @@ { "name": "twenty-front", - "version": "0.22.0", + "version": "0.23.0", "private": true, "type": "module", "scripts": { diff --git a/packages/twenty-server/package.json b/packages/twenty-server/package.json index f389bc07a96c..1b7eca8021e8 100644 --- a/packages/twenty-server/package.json +++ b/packages/twenty-server/package.json @@ -1,6 +1,6 @@ { "name": "twenty-server", - "version": "0.22.0", + "version": "0.23.0", "description": "", "author": "", "private": true, diff --git a/packages/twenty-server/src/database/commands/upgrade-version/0-23/0-23-upgrade-version.command.ts b/packages/twenty-server/src/database/commands/upgrade-version/0-23/0-23-upgrade-version.command.ts index ac4c7d28734b..ac1cc0ea0344 100644 --- a/packages/twenty-server/src/database/commands/upgrade-version/0-23/0-23-upgrade-version.command.ts +++ b/packages/twenty-server/src/database/commands/upgrade-version/0-23/0-23-upgrade-version.command.ts @@ -7,6 +7,7 @@ import { MigrateMessageChannelSyncStatusEnumCommand } from 'src/database/command import { SetWorkspaceActivationStatusCommand } from 'src/database/commands/upgrade-version/0-23/0-23-set-workspace-activation-status.command'; import { UpdateActivitiesCommand } from 'src/database/commands/upgrade-version/0-23/0-23-update-activities.command'; import { UpdateFileFolderStructureCommand } from 'src/database/commands/upgrade-version/0-23/0-23-update-file-folder-structure.command'; +import { SyncWorkspaceMetadataCommand } from 'src/engine/workspace-manager/workspace-sync-metadata/commands/sync-workspace-metadata.command'; interface UpdateTo0_23CommandOptions { workspaceId?: string; @@ -18,6 +19,7 @@ interface UpdateTo0_23CommandOptions { }) export class UpgradeTo0_23Command extends CommandRunner { constructor( + private readonly syncWorkspaceMetadataCommand: SyncWorkspaceMetadataCommand, private readonly updateFileFolderStructureCommandOptions: UpdateFileFolderStructureCommand, private readonly migrateLinkFieldsToLinks: MigrateLinkFieldsToLinksCommand, private readonly migrateDomainNameFromTextToLinks: MigrateDomainNameFromTextToLinksCommand, @@ -54,6 +56,10 @@ export class UpgradeTo0_23Command extends CommandRunner { _passedParam, options, ); + await this.syncWorkspaceMetadataCommand.run(_passedParam, { + ...options, + force: true, + }); await this.updateActivitiesCommand.run(_passedParam, options); await this.backfillNewOnboardingUserVarsCommand.run(_passedParam, options); } diff --git a/packages/twenty-server/src/database/commands/upgrade-version/0-23/0-23-upgrade-version.module.ts b/packages/twenty-server/src/database/commands/upgrade-version/0-23/0-23-upgrade-version.module.ts index 5f5d28e02b92..05fc1396cecd 100644 --- a/packages/twenty-server/src/database/commands/upgrade-version/0-23/0-23-upgrade-version.module.ts +++ b/packages/twenty-server/src/database/commands/upgrade-version/0-23/0-23-upgrade-version.module.ts @@ -21,10 +21,12 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat import { ObjectMetadataModule } from 'src/engine/metadata-modules/object-metadata/object-metadata.module'; import { WorkspaceCacheVersionModule } from 'src/engine/metadata-modules/workspace-cache-version/workspace-cache-version.module'; import { WorkspaceStatusModule } from 'src/engine/workspace-manager/workspace-status/workspace-manager.module'; +import { WorkspaceSyncMetadataCommandsModule } from 'src/engine/workspace-manager/workspace-sync-metadata/commands/workspace-sync-metadata-commands.module'; import { ViewModule } from 'src/modules/view/view.module'; @Module({ imports: [ + WorkspaceSyncMetadataCommandsModule, TypeOrmModule.forFeature([Workspace], 'core'), FileStorageModule, OnboardingModule, diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration-builder/factories/workspace-migration-field.factory.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration-builder/factories/workspace-migration-field.factory.ts index adda57f20dea..a79838dfbf16 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration-builder/factories/workspace-migration-field.factory.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration-builder/factories/workspace-migration-field.factory.ts @@ -1,5 +1,7 @@ import { Injectable } from '@nestjs/common'; +import diff from 'microdiff'; + import { WorkspaceMigrationBuilderAction } from 'src/engine/workspace-manager/workspace-migration-builder/interfaces/workspace-migration-builder-action.interface'; import { @@ -126,30 +128,66 @@ export class WorkspaceMigrationFieldFactory { continue; } - const migrations: WorkspaceMigrationTableAction[] = [ - { - name: computeObjectTargetTable( - originalObjectMetadataMap[ - fieldMetadataUpdate.current.objectMetadataId - ], - ), - action: WorkspaceMigrationTableActionType.ALTER, - columns: this.workspaceMigrationFactory.createColumnActions( - WorkspaceMigrationColumnActionType.ALTER, - fieldMetadataUpdate.current, - fieldMetadataUpdate.altered, - ), + const columnActions = this.workspaceMigrationFactory.createColumnActions( + WorkspaceMigrationColumnActionType.ALTER, + fieldMetadataUpdate.current, + fieldMetadataUpdate.altered, + ); + + const isMigrationNeeded = columnActions.reduce( + (result, currentColumnAction) => { + if ( + currentColumnAction.action === + WorkspaceMigrationColumnActionType.CREATE || + currentColumnAction.action === + WorkspaceMigrationColumnActionType.DROP + ) { + return true; + } + + if ( + currentColumnAction.action === + WorkspaceMigrationColumnActionType.ALTER + ) { + return ( + diff( + currentColumnAction.currentColumnDefinition, + currentColumnAction.alteredColumnDefinition, + ).length > 0 + ); + } + + return result; }, - ]; - - workspaceMigrations.push({ - workspaceId: fieldMetadataUpdate.current.workspaceId, - name: generateMigrationName( - `update-${fieldMetadataUpdate.altered.name}`, - ), - isCustom: false, - migrations, - }); + false, + ); + + if (isMigrationNeeded) { + const migrations: WorkspaceMigrationTableAction[] = [ + { + name: computeObjectTargetTable( + originalObjectMetadataMap[ + fieldMetadataUpdate.current.objectMetadataId + ], + ), + action: WorkspaceMigrationTableActionType.ALTER, + columns: this.workspaceMigrationFactory.createColumnActions( + WorkspaceMigrationColumnActionType.ALTER, + fieldMetadataUpdate.current, + fieldMetadataUpdate.altered, + ), + }, + ]; + + workspaceMigrations.push({ + workspaceId: fieldMetadataUpdate.current.workspaceId, + name: generateMigrationName( + `update-${fieldMetadataUpdate.altered.name}`, + ), + isCustom: false, + migrations, + }); + } } return workspaceMigrations; diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/workspace-sync-metadata-commands.module.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/workspace-sync-metadata-commands.module.ts index 1178966443ab..0ad0593eaed4 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/workspace-sync-metadata-commands.module.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/workspace-sync-metadata-commands.module.ts @@ -31,5 +31,6 @@ import { SyncWorkspaceLoggerService } from './services/sync-workspace-logger.ser ConvertRecordPositionsToIntegers, SyncWorkspaceLoggerService, ], + exports: [SyncWorkspaceMetadataCommand], }) export class WorkspaceSyncMetadataCommandsModule {} diff --git a/packages/twenty-ui/package.json b/packages/twenty-ui/package.json index a0788e34553f..b5b103136889 100644 --- a/packages/twenty-ui/package.json +++ b/packages/twenty-ui/package.json @@ -1,6 +1,6 @@ { "name": "twenty-ui", - "version": "0.22.0", + "version": "0.23.0", "type": "module", "main": "./src/index.ts", "exports": { diff --git a/packages/twenty-website/package.json b/packages/twenty-website/package.json index fd47048b5a4f..20bdc9f677f4 100644 --- a/packages/twenty-website/package.json +++ b/packages/twenty-website/package.json @@ -1,6 +1,6 @@ { "name": "twenty-website", - "version": "0.22.0", + "version": "0.23.0", "private": true, "scripts": { "nx": "NX_DEFAULT_PROJECT=twenty-website node ../../node_modules/nx/bin/nx.js", diff --git a/packages/twenty-website/src/content/developers/self-hosting/upgrade-guide.mdx b/packages/twenty-website/src/content/developers/self-hosting/upgrade-guide.mdx index 69528bed37d7..caeb20716755 100644 --- a/packages/twenty-website/src/content/developers/self-hosting/upgrade-guide.mdx +++ b/packages/twenty-website/src/content/developers/self-hosting/upgrade-guide.mdx @@ -30,6 +30,15 @@ yarn command:prod workspace:sync-metadata -f yarn command:prod upgrade-0.22 ``` +## v0.22.0 to v0.23.0 + +Run the following commands: + +``` +yarn database:migrate:prod +yarn command:prod upgrade-0.23 +``` + The `yarn database:migrate:prod` command will apply the migrations to the Database. The `yarn command:prod workspace:sync-metadata -f` command will sync the definition of standard objects to the metadata tables and apply to required migrations to existing workspaces. The `yarn command:prod upgrade-0.22` command will apply specific data transformations to adapt to the new object defaultRequestInstrumentationOptions.