From cbb1454ef84d58e9aa1332e99b475633d1d74095 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Mon, 5 Aug 2024 23:05:12 +0200 Subject: [PATCH] Fix --- .vscode/launch.json | 3 +- .../workspace-migration-field.factory.ts | 43 ++++++++++++++++--- 2 files changed, 37 insertions(+), 9 deletions(-) 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(