From 90aad93356d487fdc088ce0f8367cebc815b82cd Mon Sep 17 00:00:00 2001 From: Mohamed Marrouchi Date: Wed, 15 Jan 2025 15:53:44 +0100 Subject: [PATCH] fix: update migration to populate the message attachments with extra attributes --- .../migrations/1735836154221-v-2-2-0.migration.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/api/src/migration/migrations/1735836154221-v-2-2-0.migration.ts b/api/src/migration/migrations/1735836154221-v-2-2-0.migration.ts index 640777d6..052e02d7 100644 --- a/api/src/migration/migrations/1735836154221-v-2-2-0.migration.ts +++ b/api/src/migration/migrations/1735836154221-v-2-2-0.migration.ts @@ -602,7 +602,7 @@ const migrateAttachmentContents = async ( * * @returns Resolves when the migration process is complete. */ -const migrateAttachmentMessages = async ({ +const migrateAndPopulateAttachmentMessages = async ({ logger, http, attachmentService, @@ -636,6 +636,16 @@ const migrateAttachmentMessages = async ({ msg.message.attachment.payload ) { if ('attachment_id' in msg.message.attachment.payload) { + // Add extra attrs + await attachmentService.updateOne( + msg.message.attachment.payload.attachment_id, + { + ownerType: msg.sender ? 'Subscriber' : 'User', + owner: msg.sender ? msg.sender : adminUser.id, + context: 'message_attachment', + }, + ); + // Rename `attachment_id` to `id` await updateAttachmentId( msg._id, msg.message.attachment.payload.attachment_id as string, @@ -707,7 +717,7 @@ module.exports = { await migrateAttachmentContents(MigrationAction.UP, services); // Given the complexity and inconsistency data, this method does not have // a revert equivalent, at the same time, thus, it doesn't "unset" any attribute - await migrateAttachmentMessages(services); + await migrateAndPopulateAttachmentMessages(services); await populateBlockAttachments(services); await populateSettingAttachments(services); await populateUserAvatars(services);