remove direction from messages (#20026)

This was a leftover column removed in
https://github.com/twentyhq/twenty/pull/6743 but was accidentally added
again when we migrated to `buildMessageStandardFlatFieldMetadatas` from
workspace decorator

/closes #20011
This commit is contained in:
neo773
2026-05-05 18:54:25 +05:30
committed by GitHub
parent e50adaff2d
commit d040756fcf
6 changed files with 1065 additions and 1038 deletions

View File

@@ -21432,47 +21432,6 @@ export const mockedStandardObjectMetadataQueryResult: ObjectMetadataItemsQuery =
"relation": null,
"morphRelations": null
},
{
"__typename": "Field",
"id": "5b775671-2f37-4513-9485-c4b76c746156",
"universalIdentifier": "20202020-0203-4118-8e2a-05b9bdae6dab",
"type": "SELECT",
"name": "direction",
"label": "Direction",
"description": "Message Direction",
"icon": "IconDirection",
"isCustom": false,
"isActive": true,
"isSystem": false,
"isUIReadOnly": true,
"isNullable": false,
"isUnique": false,
"createdAt": "2026-04-10T08:55:56.200Z",
"updatedAt": "2026-04-10T08:55:56.200Z",
"defaultValue": "'INCOMING'",
"options": [
{
"id": "20202020-7b52-47d2-abd8-e96a4295f9a6",
"color": "green",
"label": "Incoming",
"value": "INCOMING",
"position": 0
},
{
"id": "20202020-11cb-42be-8df7-709ad53f90f9",
"color": "blue",
"label": "Outgoing",
"value": "OUTGOING",
"position": 1
}
],
"settings": null,
"isLabelSyncedWithName": false,
"morphId": null,
"applicationId": "dd6a5463-023d-4a10-855f-a4abaf32c1ec",
"relation": null,
"morphRelations": null
},
{
"__typename": "Field",
"id": "d87675ee-1d19-4658-8037-daec3e00b718",

View File

@@ -1,6 +1,7 @@
import { Module } from '@nestjs/common';
import { WorkspaceIteratorModule } from 'src/database/commands/command-runners/workspace-iterator.module';
import { DropMessageDirectionFieldCommand } from 'src/database/commands/upgrade-version-command/2-3/2-3-workspace-command-1777400000000-drop-message-direction-field.command';
import { BackfillImageIdentifierFieldMetadataIdCommand } from 'src/database/commands/upgrade-version-command/2-3/2-3-workspace-command-1777920000000-backfill-image-identifier-field-metadata-id.command';
import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache.module';
@@ -13,6 +14,9 @@ import { WorkspaceMigrationModule } from 'src/engine/workspace-manager/workspace
WorkspaceIteratorModule,
WorkspaceMigrationModule,
],
providers: [BackfillImageIdentifierFieldMetadataIdCommand],
providers: [
DropMessageDirectionFieldCommand,
BackfillImageIdentifierFieldMetadataIdCommand,
],
})
export class V2_3_UpgradeVersionCommandModule {}

View File

@@ -0,0 +1,104 @@
import { Command } from 'nest-commander';
import { ActiveOrSuspendedWorkspaceCommandRunner } from 'src/database/commands/command-runners/active-or-suspended-workspace.command-runner';
import { WorkspaceIteratorService } from 'src/database/commands/command-runners/workspace-iterator.service';
import { type RunOnWorkspaceArgs } from 'src/database/commands/command-runners/workspace.command-runner';
import { ApplicationService } from 'src/engine/core-modules/application/application.service';
import { RegisteredWorkspaceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-workspace-command.decorator';
import { findFlatEntityByUniversalIdentifier } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-universal-identifier.util';
import { type FlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata.type';
import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
import { WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service';
const MESSAGE_DIRECTION_FIELD_UNIVERSAL_IDENTIFIER =
'20202020-0203-4118-8e2a-05b9bdae6dab';
@RegisteredWorkspaceCommand('2.3.0', 1777400000000)
@Command({
name: 'upgrade:2-3:drop-message-direction-field',
description:
'Drop the leftover message.direction field metadata and its workspace column',
})
export class DropMessageDirectionFieldCommand extends ActiveOrSuspendedWorkspaceCommandRunner {
constructor(
protected readonly workspaceIteratorService: WorkspaceIteratorService,
private readonly applicationService: ApplicationService,
private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService,
private readonly workspaceCacheService: WorkspaceCacheService,
) {
super(workspaceIteratorService);
}
override async runOnWorkspace({
workspaceId,
options,
}: RunOnWorkspaceArgs): Promise<void> {
const isDryRun = options.dryRun ?? false;
this.logger.log(
`${isDryRun ? '[DRY RUN] ' : ''}Starting message.direction field removal for workspace ${workspaceId}`,
);
const { flatFieldMetadataMaps } =
await this.workspaceCacheService.getOrRecompute(workspaceId, [
'flatFieldMetadataMaps',
]);
const directionFieldMetadata =
findFlatEntityByUniversalIdentifier<FlatFieldMetadata>({
flatEntityMaps: flatFieldMetadataMaps,
universalIdentifier: MESSAGE_DIRECTION_FIELD_UNIVERSAL_IDENTIFIER,
});
if (!directionFieldMetadata) {
this.logger.log(
`message.direction field already absent for workspace ${workspaceId}`,
);
return;
}
if (isDryRun) {
this.logger.log(
`[DRY RUN] Would delete message.direction field for workspace ${workspaceId}`,
);
return;
}
const { twentyStandardFlatApplication } =
await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow(
{ workspaceId },
);
const validateAndBuildResult =
await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunWorkspaceMigration(
{
allFlatEntityOperationByMetadataName: {
fieldMetadata: {
flatEntityToCreate: [],
flatEntityToDelete: [directionFieldMetadata],
flatEntityToUpdate: [],
},
},
workspaceId,
applicationUniversalIdentifier:
twentyStandardFlatApplication.universalIdentifier,
},
);
if (validateAndBuildResult.status === 'fail') {
this.logger.error(
`Failed to delete message.direction field:\n${JSON.stringify(validateAndBuildResult, null, 2)}`,
);
throw new Error(
`Failed to delete message.direction field for workspace ${workspaceId}`,
);
}
this.logger.log(
`Deleted message.direction field for workspace ${workspaceId}`,
);
}
}

View File

@@ -212,40 +212,6 @@ export const buildMessageStandardFlatFieldMetadatas = ({
twentyStandardApplicationId,
now,
}),
direction: createStandardFieldFlatMetadata({
objectName,
workspaceId,
context: {
fieldName: 'direction',
type: FieldMetadataType.SELECT,
label: i18nLabel(msg`Direction`),
description: i18nLabel(msg`Message Direction`),
icon: 'IconDirection',
isNullable: false,
isUIReadOnly: true,
defaultValue: "'INCOMING'",
options: [
{
id: '20202020-7b52-47d2-abd8-e96a4295f9a6',
value: 'INCOMING',
label: i18nLabel(msg`Incoming`),
position: 0,
color: 'green',
},
{
id: '20202020-11cb-42be-8df7-709ad53f90f9',
value: 'OUTGOING',
label: i18nLabel(msg`Outgoing`),
position: 1,
color: 'blue',
},
],
},
standardObjectMetadataRelatedEntityIds,
dependencyFlatEntityMaps,
twentyStandardApplicationId,
now,
}),
subject: createStandardFieldFlatMetadata({
objectName,
workspaceId,

View File

@@ -1651,9 +1651,6 @@ export const STANDARD_OBJECTS = {
messageThread: {
universalIdentifier: '20202020-30f2-4ccd-9f5c-e41bb9d26214',
},
direction: {
universalIdentifier: '20202020-0203-4118-8e2a-05b9bdae6dab',
},
subject: { universalIdentifier: '20202020-52d1-4036-b9ae-84bd722bb37a' },
text: { universalIdentifier: '20202020-d2ee-4e7e-89de-9a0a9044a143' },
receivedAt: {