Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesBochet committed Aug 5, 2024
1 parent 72a69d5 commit cbb1454
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
"nx",
"run",
"twenty-server:command",
"my-command",
"--my-parameter value",
"upgrade-0.23",
],
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart",
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit cbb1454

Please sign in to comment.