Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/meteor/server/startup/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ import './v328';
import './v329';
import './v330';
import './v331';
import './v332';

export * from './xrun';
53 changes: 53 additions & 0 deletions apps/meteor/server/startup/migrations/v332.ts
Original file line number Diff line number Diff line change
@@ -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 },
},
Comment on lines +11 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical typo: contactUssername should be contactUsername.

Line 15 has a typo with double 's' in contactUssername. This breaks the filter logic—documents that already have contactUsername populated will still match because contactUssername (the typo) doesn't exist on any document. This will cause the migration to unnecessarily process and update records that should be skipped.

🔎 Proposed fix
 			{
 				$match: {
 					external: false,
 					contactId: { $exists: true },
 					contactName: { $exists: false },
-					contactUssername: { $exists: false },
+					contactUsername: { $exists: false },
 				},
 			},
🤖 Prompt for AI Agents
In apps/meteor/server/startup/migrations/v332.ts around lines 11 to 16, the
$match filter contains a typo "contactUssername" (double 's') which prevents
correct filtering; change that key to "contactUsername" so the query checks the
actual field, update any other occurrences of the misspelled field in this file,
and run the migration/dry-run to verify only documents missing contactUsername
are processed.

},

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