From c8ae694f1f0a5140d077a831f7b0cb0c77e2ee28 Mon Sep 17 00:00:00 2001 From: Pierre Lehnen Date: Fri, 19 Dec 2025 15:57:06 -0300 Subject: [PATCH] chore: Migrate user names into existing Call History entries --- .../meteor/server/startup/migrations/index.ts | 1 + apps/meteor/server/startup/migrations/v332.ts | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 apps/meteor/server/startup/migrations/v332.ts diff --git a/apps/meteor/server/startup/migrations/index.ts b/apps/meteor/server/startup/migrations/index.ts index 18f68f260e35c..969a4b1a668be 100644 --- a/apps/meteor/server/startup/migrations/index.ts +++ b/apps/meteor/server/startup/migrations/index.ts @@ -37,5 +37,6 @@ import './v328'; import './v329'; import './v330'; import './v331'; +import './v332'; export * from './xrun'; diff --git a/apps/meteor/server/startup/migrations/v332.ts b/apps/meteor/server/startup/migrations/v332.ts new file mode 100644 index 0000000000000..61852faf7b163 --- /dev/null +++ b/apps/meteor/server/startup/migrations/v332.ts @@ -0,0 +1,53 @@ +import { CallHistory, Users } from '@rocket.chat/models'; + +import { addMigration } from '../../lib/migrations'; + +addMigration({ + version: 332, + name: 'Fill contact information on older call history entries', + async up() { + const cursor = CallHistory.col.aggregate([ + { + $match: { + external: false, + contactId: { $exists: true }, + contactName: { $exists: false }, + contactUssername: { $exists: false }, + }, + }, + + { + $lookup: { + from: Users.col.collectionName, + localField: 'contactId', + foreignField: '_id', + as: 'contactDetails', + }, + }, + { + $addFields: { + contactName: { $first: '$contactDetails.name' }, + contactUsername: { $first: '$contactDetails.username' }, + }, + }, + { + $project: { + contactName: 1, + contactUsername: 1, + }, + }, + { + $merge: { + into: CallHistory.col.collectionName, + on: '_id', + whenMatched: 'merge', + }, + }, + ]); + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + for await (const _item of cursor) { + // + } + }, +});