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) { + // + } + }, +});