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

38 lines
893 B

RocketChat.Migrations.add({
version: 94,
up() {
const query = {
'emails.address.address': { $exists: true }
};
RocketChat.models.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;
}
});
const existingUser = RocketChat.models.Users.findOne({ 'emails.address': emailAddress }, { fields: { _id: 1 } });
if (existingUser) {
RocketChat.models.Users.update({
_id: user._id,
'emails.address.address': emailAddress
}, {
$unset: {
'emails.$': 1
}
});
} else {
RocketChat.models.Users.update({
_id: user._id,
'emails.address.address': emailAddress
}, {
$set: {
'emails.$.address': emailAddress
}
});
}
});
}
});