Skip to content

Commit 7254b63

Browse files
pierre-lehnen-rcggazzo
authored andcommitted
chore!: migrate user names into existing Call History entries (#37898)
1 parent a6845d9 commit 7254b63

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

apps/meteor/server/startup/migrations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ import './v328';
3737
import './v329';
3838
import './v330';
3939
import './v331';
40+
import './v332';
4041

4142
export * from './xrun';
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { CallHistory, Users } from '@rocket.chat/models';
2+
3+
import { addMigration } from '../../lib/migrations';
4+
5+
addMigration({
6+
version: 332,
7+
name: 'Fill contact information on older call history entries',
8+
async up() {
9+
const cursor = CallHistory.col.aggregate([
10+
{
11+
$match: {
12+
external: false,
13+
contactId: { $exists: true },
14+
contactName: { $exists: false },
15+
contactUsername: { $exists: false },
16+
},
17+
},
18+
19+
{
20+
$lookup: {
21+
from: Users.col.collectionName,
22+
localField: 'contactId',
23+
foreignField: '_id',
24+
as: 'contactDetails',
25+
},
26+
},
27+
{
28+
$addFields: {
29+
contactName: { $first: '$contactDetails.name' },
30+
contactUsername: { $first: '$contactDetails.username' },
31+
},
32+
},
33+
{
34+
$project: {
35+
contactName: 1,
36+
contactUsername: 1,
37+
},
38+
},
39+
{
40+
$merge: {
41+
into: CallHistory.col.collectionName,
42+
on: '_id',
43+
whenMatched: 'merge',
44+
},
45+
},
46+
]);
47+
48+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
49+
for await (const _item of cursor) {
50+
//
51+
}
52+
},
53+
});

0 commit comments

Comments
 (0)