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

73 lines
1.2 KiB

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