Skip to content
Snippets Groups Projects
Unverified Commit 12c1cf6e authored by Diego Sampaio's avatar Diego Sampaio Committed by GitHub
Browse files

[BREAK] Upgrade to version 5.0 can be done only from version 4.x (#26100)

parent 4d99ef01
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 670 deletions
import './v174';
import './v175';
import './v176';
import './v177';
import './v178';
import './v179';
import './v180';
import './v182';
import './v183';
import './v184';
import './v185';
import './v186';
import './v187';
import './v188';
import './v189';
import './v190';
import './v191';
import './v192';
import './v193';
import './v194';
import './v195';
import './v196';
import './v197';
import './v198';
import './v199';
import './v200';
import './v201';
import './v202';
import './v203';
import './v204';
import './v205';
import './v206';
import './v207';
import './v208';
import './v209';
import './v210';
import './v211';
import './v212';
import './v213';
import './v214';
import './v215';
import './v216';
import './v217';
import './v218';
import './v219';
import './v220';
import './v221';
import './v222';
import './v223';
import './v224';
import './v225';
import './v226';
import './v227';
import './v228';
import './v229';
import './v230';
import './v231';
import './v232';
import './v233';
import './v234';
import './v235';
......
import { Permissions } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
const appRolePermissions = [
'api-bypass-rate-limit',
'create-c',
'create-d',
'create-p',
'join-without-join-code',
'leave-c',
'leave-p',
'send-many-messages',
'view-c-room',
'view-d-room',
'view-joined-room',
];
addMigration({
version: 174,
up() {
return Permissions.update({ _id: { $in: appRolePermissions } }, { $addToSet: { roles: 'app' } }, { multi: true });
},
down() {
return Permissions.update({ _id: { $in: appRolePermissions } }, { $pull: { roles: 'app' } }, { multi: true });
},
});
import { Settings } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
import { theme } from '../../../app/theme/server/server';
addMigration({
version: 175,
up() {
Promise.await(
Promise.all(
Object.entries(theme.variables)
.filter(([, value]) => value.type === 'color')
.map(([key, { editor }]) =>
Settings.update(
{ _id: `theme-color-${key}` },
{
$set: {
packageEditor: editor,
},
},
),
),
),
);
},
});
import { Settings } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 176,
up() {
return Settings.deleteOne({ _id: 'Livechat', type: 'group' });
},
});
import { Settings } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 177,
up() {
// Disable auto opt in for existent installations
Settings.update(
{
_id: 'Accounts_TwoFactorAuthentication_By_Email_Auto_Opt_In',
},
{
$set: {
value: false,
},
},
{
upsert: true,
},
);
},
});
import { Settings } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 178,
up() {
return Settings.removeById('Livechat_enable_inquiry_fetch_by_stream');
},
});
import { Meteor } from 'meteor/meteor';
import Future from 'fibers/future';
import { addMigration } from '../../lib/migrations';
import { Rooms } from '../../../app/models/server';
const batchSize = 5000;
const getIds = (_id) => {
// DM alone
if (_id.length === 17) {
return [_id];
}
// DM with rocket.cat
if (_id.match(/rocket\.cat/)) {
return ['rocket.cat', _id.replace('rocket.cat', '')];
}
const total = _id.length;
// regular DMs
const id1 = _id.substr(0, Math.ceil(total / 2));
const id2 = _id.substr(Math.ceil(total / 2));
// buggy (?) DM alone but with duplicated _id
// if (id1 === id2) {
// return [id1];
// }
return [id1, id2];
};
async function migrateDMs(models, total, current) {
const { roomCollection } = models;
console.log(`DM rooms schema migration ${current}/${total}`);
const items = await roomCollection
.find({ t: 'd', uids: { $exists: false } }, { fields: { _id: 1 } })
.limit(batchSize)
.toArray();
const actions = items.map((room) => ({
updateOne: {
filter: { _id: room._id },
update: {
$set: {
uids: getIds(room._id),
},
},
},
}));
if (actions.length === 0) {
return;
}
const batch = await roomCollection.bulkWrite(actions, { ordered: false });
if (actions.length === batchSize) {
await batch;
return migrateDMs(models, total, current + batchSize);
}
return batch;
}
addMigration({
version: 179,
up() {
const fut = new Future();
const roomCollection = Rooms.model.rawCollection();
Meteor.setTimeout(async () => {
const rooms = roomCollection.find({ t: 'd' });
const total = await rooms.count();
await rooms.close();
if (total < batchSize * 10) {
await migrateDMs({ roomCollection }, total, 0);
return fut.return();
}
console.log('Changing schema of Direct Message rooms, this may take a long time ...');
await migrateDMs({ roomCollection }, total, 0);
console.log('Changing schema of Direct Message rooms finished.');
fut.return();
}, 200);
fut.wait();
},
});
import { addMigration } from '../../lib/migrations';
import { LivechatRooms, LivechatInquiry } from '../../../app/models/server';
addMigration({
version: 180,
up() {
// Remove Old Omnichannel Inquiries related to rooms already closed
LivechatInquiry.find().forEach((inquiry) => {
const { rid, status } = inquiry;
if (status === 'closed') {
return LivechatInquiry.removeByRoomId(rid);
}
const room = LivechatRooms.findOneById(rid, { closedAt: 1 });
if (!room || room.closedAt) {
LivechatInquiry.removeByRoomId(rid);
}
});
},
});
import { Analytics } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 182,
up() {
Analytics.deleteMany({});
},
});
import { Meteor } from 'meteor/meteor';
import { Random } from 'meteor/random';
import { Settings, Uploads } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
import { Rooms, Messages, Subscriptions, Users } from '../../../app/models/server';
const unifyRooms = (room) => {
// verify if other DM already exists
const other = Rooms.findOne({
_id: { $ne: room._id },
t: 'd',
uids: room.uids,
});
// we need to at least change the _id of the current room, so remove it
Rooms.remove({ _id: room._id });
const newId = (other && other._id) || Random.id();
if (!other) {
// create the same room with different _id
Rooms.insert({
...room,
_id: newId,
});
// update subscription to point to new room _id
Subscriptions.update(
{ rid: room._id },
{
$set: {
rid: newId,
},
},
{ multi: true },
);
return newId;
}
// the other room exists already, so just remove the subscription of the wrong room
Subscriptions.remove({ rid: room._id });
return newId;
};
const fixSelfDMs = () => {
Rooms.find({
t: 'd',
uids: { $size: 1 },
}).forEach((room) => {
if (!Array.isArray(room.uids) || room._id !== room.uids[0]) {
return;
}
const correctId = unifyRooms(room);
// move things to correct room
Messages.update(
{ rid: room._id },
{
$set: {
rid: correctId,
},
},
{ multi: true },
);
// Fix error of upload permission check using Meteor.userId()
Meteor.runAsUser(room.uids[0], async () => {
await Uploads.update(
{ rid: room._id },
{
$set: {
rid: correctId,
},
},
{ multi: true },
);
});
});
};
const fixDiscussions = () => {
Rooms.find({ t: 'd', prid: { $exists: true } }, { fields: { _id: 1 } }).forEach(({ _id }) => {
const { u } = Messages.findOne({ drid: _id }, { fields: { u: 1 } }) || {};
Rooms.update(
{ _id },
{
$set: {
t: 'p',
name: Random.id(),
u,
ro: false,
default: false,
sysMes: true,
},
$unset: {
usernames: 1,
uids: 1,
},
},
);
});
};
const fixUserSearch = async () => {
const setting = await Settings.findOneById('Accounts_SearchFields', { projection: { value: 1 } });
const value = setting?.value?.trim();
if (value === '' || value === 'username, name') {
await Settings.updateValueById('Accounts_SearchFields', 'username, name, bio');
}
Users.tryDropIndex('name_text_username_text_bio_text');
};
addMigration({
version: 183,
up() {
fixDiscussions();
fixSelfDMs();
return fixUserSearch();
},
});
import { Settings } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 184,
up() {
// Set SAML signature validation type to 'Either'
Settings.update(
{
_id: 'SAML_Custom_Default_signature_validation_type',
},
{
$set: {
value: 'Either',
},
},
{
upsert: true,
},
);
},
});
import { Settings } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 185,
async up() {
const setting = await Settings.findOne({ _id: 'Message_SetNameToAliasEnabled' });
if (setting?.value) {
await Settings.update(
{ _id: 'UI_Use_Real_Name' },
{
$set: {
value: true,
},
},
);
}
return Settings.removeById('Message_SetNameToAliasEnabled');
},
});
import { LivechatInquiry } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 186,
up() {
LivechatInquiry.find({}, { fields: { _id: 1, ts: 1 } }).forEach((inquiry) => {
const { _id, ts } = inquiry;
LivechatInquiry.update(
{ _id },
{
$set: {
queueOrder: 1,
estimatedWaitingTimeQueue: 0,
estimatedServiceTimeAt: ts,
},
},
);
});
},
});
import { Mongo } from 'meteor/mongo';
import { NotificationQueue, Settings } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
function convertNotification(notification) {
try {
const { userId } = JSON.parse(notification.query);
const username = notification.payload.sender?.username;
const roomName = notification.title !== username ? notification.title : '';
const message = roomName === '' ? notification.text : notification.text.replace(`${username}: `, '');
return {
_id: notification._id,
uid: userId,
rid: notification.payload.rid,
mid: notification.payload.messageId,
ts: notification.createdAt,
items: [
{
type: 'push',
data: {
payload: notification.payload,
roomName,
username,
message,
badge: notification.badge,
category: notification.apn?.category,
},
},
],
};
} catch (e) {
//
}
}
async function migrateNotifications() {
const notificationsCollection = new Mongo.Collection('_raix_push_notifications');
const date = new Date();
date.setHours(date.getHours() - 2); // 2 hours ago;
const cursor = notificationsCollection.rawCollection().find({
createdAt: { $gte: date },
});
for await (const notification of cursor) {
const newNotification = convertNotification(notification);
if (newNotification) {
await NotificationQueue.insertOne(newNotification);
}
}
return notificationsCollection.rawCollection().drop();
}
addMigration({
version: 187,
async up() {
await Settings.removeById('Push_send_interval');
await Settings.removeById('Push_send_batch_size');
await Settings.removeById('Push_debug');
await Settings.removeById('Notifications_Always_Notify_Mobile');
try {
await migrateNotifications();
} catch (err) {
// Ignore if the collection does not exist
if (!err.code || err.code !== 26) {
throw err;
}
}
},
});
import { Permissions } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
const newRolePermissions = ['view-d-room', 'view-p-room'];
const roleId = 'guest';
addMigration({
version: 188,
up() {
return Permissions.update({ _id: { $in: newRolePermissions } }, { $addToSet: { roles: roleId } }, { multi: true });
},
});
import { Settings } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 189,
async up() {
await Settings.removeById('Livechat_Knowledge_Enabled');
await Settings.removeById('Livechat_Knowledge_Apiai_Key');
await Settings.removeById('Livechat_Knowledge_Apiai_Language');
},
});
import { Settings, Subscriptions } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 190,
up() {
// Remove unused settings
Promise.await(Settings.removeById('Accounts_Default_User_Preferences_desktopNotificationDuration'));
Promise.await(
Subscriptions.col.updateMany(
{
desktopNotificationDuration: {
$exists: true,
},
},
{
$unset: {
desktopNotificationDuration: 1,
},
},
),
);
},
});
import { Settings } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 191,
async up() {
return Settings.deleteMany({ _id: /theme-color-status/ });
},
});
import { addMigration } from '../../lib/migrations';
import { Messages, Rooms } from '../../../app/models/server';
import { trash } from '../../database/trash';
addMigration({
version: 192,
up() {
try {
trash._dropIndex({ collection: 1 });
} catch {
//
}
Messages.tryDropIndex({ rid: 1, ts: 1 });
Rooms.tryDropIndex({ 'tokenpass.tokens.token': 1 });
Rooms.tryEnsureIndex({ 'tokenpass.tokens.token': 1 }, { sparse: true });
Rooms.tryDropIndex({ default: 1 });
Rooms.tryEnsureIndex({ default: 1 }, { sparse: true });
Rooms.tryDropIndex({ featured: 1 });
Rooms.tryEnsureIndex({ featured: 1 }, { sparse: true });
Rooms.tryDropIndex({ muted: 1 });
Rooms.tryEnsureIndex({ muted: 1 }, { sparse: true });
},
});
import { Rooms } from '@rocket.chat/models';
import { addMigration } from '../../lib/migrations';
addMigration({
version: 193,
up() {
Promise.await(
Rooms.col.updateMany(
{
sysMes: 'subscription_role_added',
},
{
$set: {
'sysMes.$': 'subscription-role-added',
},
},
),
);
Promise.await(
Rooms.col.updateMany(
{
sysMes: 'subscription_role_removed',
},
{
$set: {
'sysMes.$': 'subscription-role-removed',
},
},
),
);
},
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment