From 3706da9bcbb5f1209801cf872d466978f9a7a10f Mon Sep 17 00:00:00 2001 From: Etienne <45695613+etiennejouan@users.noreply.github.com> Date: Wed, 18 Feb 2026 13:52:13 +0100 Subject: [PATCH] v1.18 - Fix command (#18032) Same as here https://github.com/twentyhq/twenty/pull/18016 --- ...y-rich-text-attachment-file-ids.command.ts | 111 +++++++++--------- 1 file changed, 58 insertions(+), 53 deletions(-) diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/1-18/1-18-migrate-activity-rich-text-attachment-file-ids.command.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/1-18/1-18-migrate-activity-rich-text-attachment-file-ids.command.ts index 15d6ebbaf7..4391c9abbd 100644 --- a/packages/twenty-server/src/database/commands/upgrade-version-command/1-18/1-18-migrate-activity-rich-text-attachment-file-ids.command.ts +++ b/packages/twenty-server/src/database/commands/upgrade-version-command/1-18/1-18-migrate-activity-rich-text-attachment-file-ids.command.ts @@ -26,6 +26,7 @@ import { findFlatEntityByUniversalIdentifier } from 'src/engine/metadata-modules import { type FlatObjectMetadata } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata.type'; import { GlobalWorkspaceOrmManager } from 'src/engine/twenty-orm/global-workspace-datasource/global-workspace-orm.manager'; import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository'; +import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util'; import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service'; import { AttachmentWorkspaceEntity } from 'src/modules/attachment/standard-objects/attachment.workspace-entity'; import { NoteWorkspaceEntity } from 'src/modules/note/standard-objects/note.workspace-entity'; @@ -121,63 +122,67 @@ export class MigrateActivityRichTextAttachmentFileIdsCommand extends ActiveOrSus ); } - const attachmentRepository = - await this.twentyORMGlobalManager.getRepository( + const systemAuthContext = buildSystemAuthContext(workspaceId); + + await this.twentyORMGlobalManager.executeInWorkspaceContext(async () => { + const attachmentRepository = + await this.twentyORMGlobalManager.getRepository( + workspaceId, + 'attachment', + { shouldBypassPermissionChecks: true }, + ); + + const noteRepository = + await this.twentyORMGlobalManager.getRepository( + workspaceId, + 'note', + { shouldBypassPermissionChecks: true }, + ); + + const taskRepository = + await this.twentyORMGlobalManager.getRepository( + workspaceId, + 'task', + { shouldBypassPermissionChecks: true }, + ); + + const fileRepository = this.coreDataSource.getRepository(FileEntity); + + await this.migrateActivityTable({ + activityRepository: noteRepository, + attachmentRepository, + fileRepository, + activityType: 'note', + targetColumnName: 'targetNoteId', workspaceId, - 'attachment', - { shouldBypassPermissionChecks: true }, - ); + twentyStandardApplication: twentyStandardFlatApplication, + fileFieldMetadata: attachmentFileFieldMetadata, + isDryRun, + }); - const noteRepository = - await this.twentyORMGlobalManager.getRepository( + await this.migrateActivityTable({ + activityRepository: taskRepository, + attachmentRepository, + fileRepository, + activityType: 'task', + targetColumnName: 'targetTaskId', workspaceId, - 'note', - { shouldBypassPermissionChecks: true }, + twentyStandardApplication: twentyStandardFlatApplication, + fileFieldMetadata: attachmentFileFieldMetadata, + isDryRun, + }); + + if (!isDryRun) { + await this.featureFlagService.enableFeatureFlags( + [FeatureFlagKey.IS_FILES_FIELD_MIGRATED], + workspaceId, + ); + } + + this.logger.log( + `${isDryRun ? '[DRY RUN] ' : ''}Completed activity rich text attachment file IDs migration for workspace ${workspaceId}`, ); - - const taskRepository = - await this.twentyORMGlobalManager.getRepository( - workspaceId, - 'task', - { shouldBypassPermissionChecks: true }, - ); - - const fileRepository = this.coreDataSource.getRepository(FileEntity); - - await this.migrateActivityTable({ - activityRepository: noteRepository, - attachmentRepository, - fileRepository, - activityType: 'note', - targetColumnName: 'targetNoteId', - workspaceId, - twentyStandardApplication: twentyStandardFlatApplication, - fileFieldMetadata: attachmentFileFieldMetadata, - isDryRun, - }); - - await this.migrateActivityTable({ - activityRepository: taskRepository, - attachmentRepository, - fileRepository, - activityType: 'task', - targetColumnName: 'targetTaskId', - workspaceId, - twentyStandardApplication: twentyStandardFlatApplication, - fileFieldMetadata: attachmentFileFieldMetadata, - isDryRun, - }); - - if (!isDryRun) { - await this.featureFlagService.enableFeatureFlags( - [FeatureFlagKey.IS_FILES_FIELD_MIGRATED], - workspaceId, - ); - } - - this.logger.log( - `${isDryRun ? '[DRY RUN] ' : ''}Completed activity rich text attachment file IDs migration for workspace ${workspaceId}`, - ); + }, systemAuthContext); } private async migrateActivityTable({