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/v004.js

69 lines
1.2 KiB

RocketChat.Migrations.add({
version: 4,
up() {
RocketChat.models.Messages.tryDropIndex('rid_1');
RocketChat.models.Subscriptions.tryDropIndex('u._id_1');
console.log('Rename rn to name');
RocketChat.models.Subscriptions.update({
rn: {
$exists: true
}
}, {
$rename: {
rn: 'name'
}
}, {
multi: true
});
console.log('Adding names to rooms without name');
RocketChat.models.Rooms.find({
name: ''
}).forEach((item) => {
const name = Random.id().toLowerCase();
RocketChat.models.Rooms.setNameById(item._id, name);
return RocketChat.models.Subscriptions.update({
rid: item._id
}, {
$set: {
name
}
}, {
multi: true
});
});
console.log('Making room names unique');
RocketChat.models.Rooms.find().forEach(function(room) {
return RocketChat.models.Rooms.find({
name: room.name,
_id: {
$ne: room._id
}
}).forEach((item) => {
const name = `${ room.name }-${ Random.id(2).toLowerCase() }`;
RocketChat.models.Rooms.setNameById(item._id, name);
return RocketChat.models.Subscriptions.update({
rid: item._id
}, {
$set: {
name
}
}, {
multi: true
});
});
});
return console.log('End');
}
});