The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/server/startup/migrations/v094.js

42 lines
940 B

import { Migrations } from '../../../app/migrations';
import { Users } from '../../../app/models';
Migrations.add({
version: 94,
up() {
const query = {
'emails.address.address': { $exists: true },
};
Users.find(query, { 'emails.address.address': 1 }).forEach((user) => {
let emailAddress;
user.emails.some((email) => {
if (email.address && email.address.address) {
emailAddress = email.address.address;
return true;
}
return false;
});
const existingUser = Users.findOne({ 'emails.address': emailAddress }, { fields: { _id: 1 } });
if (existingUser) {
Users.update({
_id: user._id,
'emails.address.address': emailAddress,
}, {
$unset: {
'emails.$': 1,
},
});
} else {
Users.update({
_id: user._id,
'emails.address.address': emailAddress,
}, {
$set: {
'emails.$.address': emailAddress,
},
});
}
});
},
});