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

31 lines
960 B

import { MongoInternals } from 'meteor/mongo';
import Future from 'fibers/future';
import { addMigration } from '../../lib/migrations';
import { Rooms } from '../../../app/models/server/raw';
import { TeamRaw } from '../../../app/models/server/raw/Team';
import { TEAM_TYPE } from '../../../definition/ITeam';
async function migrateTeamNames(fut) {
const { mongo } = MongoInternals.defaultRemoteCollectionDriver();
const Team = new TeamRaw(mongo.db.collection('rocketchat_team'));
const rooms = await Rooms.find({ teamMain: true }, { projection: { name: 1, fname: 1, teamId: 1, t: 1 } }).toArray();
await Promise.all(rooms.map(async ({ name, fname, t, teamId }) => {
const update = {
name: fname || name,
type: t === 'c' ? TEAM_TYPE.PUBLIC : TEAM_TYPE.PRIVATE,
};
Team.updateNameAndType(teamId, update);
}));
fut.return();
}
addMigration({
version: 221,
up() {
const fut = new Future();
migrateTeamNames(fut);
fut.wait();
},
});