diff --git a/.vscode/launch.json b/.vscode/launch.json index 2a13f9e89cdb..a2c3db5aa664 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -44,8 +44,7 @@ "nx", "run", "twenty-server:command", - "my-command", - "--my-parameter value", + "upgrade-0.23", ], "outputCapture": "std", "internalConsoleOptions": "openOnSessionStart", 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 22155467619e..234609fa54eb 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,6 +1,6 @@ import { Injectable } from '@nestjs/common'; -import { isDeepStrictEqual } from 'util'; +import diff from 'microdiff'; import { WorkspaceMigrationBuilderAction } from 'src/engine/workspace-manager/workspace-migration-builder/interfaces/workspace-migration-builder-action.interface'; @@ -128,12 +128,41 @@ export class WorkspaceMigrationFieldFactory { continue; } - if ( - !isDeepStrictEqual( - 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; + }, + false, + ); + + if (migrationDifferences.length > 0) { const migrations: WorkspaceMigrationTableAction[] = [ { name: computeObjectTargetTable(