diff --git a/server/startup/migrations/v041.js b/server/startup/migrations/v041.js index da2b432743e51..83085e1e5c44b 100644 --- a/server/startup/migrations/v041.js +++ b/server/startup/migrations/v041.js @@ -1,10 +1,13 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 41, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Users) { - RocketChat.models.Users.update({ bot: true }, { $set: { type: 'bot' } }, { multi: true }); - RocketChat.models.Users.update({ 'profile.guest': true }, { $set: { type: 'visitor' } }, { multi: true }); - RocketChat.models.Users.update({ type: { $exists: false } }, { $set: { type: 'user' } }, { multi: true }); + if (Users) { + Users.update({ bot: true }, { $set: { type: 'bot' } }, { multi: true }); + Users.update({ 'profile.guest': true }, { $set: { type: 'visitor' } }, { multi: true }); + Users.update({ type: { $exists: false } }, { $set: { type: 'user' } }, { multi: true }); } }, }); diff --git a/server/startup/migrations/v042.js b/server/startup/migrations/v042.js index e97cb83bf8c98..275d99f1ca445 100644 --- a/server/startup/migrations/v042.js +++ b/server/startup/migrations/v042.js @@ -1,10 +1,13 @@ import { Mongo } from 'meteor/mongo'; +import { Migrations } from 'meteor/rocketchat:migrations'; +import { settings } from 'meteor/rocketchat:settings'; +import { RocketChatAssets } from 'meteor/rocketchat:assets'; -RocketChat.Migrations.add({ +Migrations.add({ version: 42, up() { - const files = RocketChat.__migration_assets_files = new Mongo.Collection('assets.files'); - const chunks = RocketChat.__migration_assets_chunks = new Mongo.Collection('assets.chunks'); + const files = new Mongo.Collection('assets.files'); + const chunks = new Mongo.Collection('assets.chunks'); const list = { 'favicon.ico': 'favicon_ico', 'favicon.svg': 'favicon', @@ -28,11 +31,11 @@ RocketChat.Migrations.add({ }); if (oldFile) { - const extension = RocketChat.Assets.mime.extension(oldFile.contentType); - RocketChat.settings.removeById(`Assets_${ from }`); - RocketChat.settings.updateById(`Assets_${ to }`, { + const extension = RocketChatAssets.mime.extension(oldFile.contentType); + settings.removeById(`Assets_${ from }`); + settings.updateById(`Assets_${ to }`, { url: `/assets/${ to }.${ extension }`, - defaultUrl: RocketChat.Assets.assets[to].defaultUrl, + defaultUrl: RocketChatAssets.assets[to].defaultUrl, }); oldFile._id = to; diff --git a/server/startup/migrations/v043.js b/server/startup/migrations/v043.js index 87867c358f49f..209d0f60e2dda 100644 --- a/server/startup/migrations/v043.js +++ b/server/startup/migrations/v043.js @@ -1,8 +1,11 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Permissions } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 43, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Permissions) { - RocketChat.models.Permissions.update({ _id: 'pin-message' }, { $addToSet: { roles: 'admin' } }); + if (Permissions) { + Permissions.update({ _id: 'pin-message' }, { $addToSet: { roles: 'admin' } }); } }, }); diff --git a/server/startup/migrations/v044.js b/server/startup/migrations/v044.js index 4906437409561..fb6f0a6f4a0f0 100644 --- a/server/startup/migrations/v044.js +++ b/server/startup/migrations/v044.js @@ -1,19 +1,22 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users, Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 44, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Users) { - RocketChat.models.Users.find({ $or: [{ 'settings.preferences.disableNewRoomNotification': { $exists: 1 } }, { 'settings.preferences.disableNewMessageNotification': { $exists: 1 } }] }).forEach(function(user) { + if (Users) { + Users.find({ $or: [{ 'settings.preferences.disableNewRoomNotification': { $exists: 1 } }, { 'settings.preferences.disableNewMessageNotification': { $exists: 1 } }] }).forEach(function(user) { const newRoomNotification = !(user && user.settings && user.settings.preferences && user.settings.preferences.disableNewRoomNotification); const newMessageNotification = !(user && user.settings && user.settings.preferences && user.settings.preferences.disableNewMessageNotification); - RocketChat.models.Users.update({ _id: user._id }, { $unset: { 'settings.preferences.disableNewRoomNotification': 1, 'settings.preferences.disableNewMessageNotification': 1 }, $set: { 'settings.preferences.newRoomNotification': newRoomNotification, 'settings.preferences.newMessageNotification': newMessageNotification } }); + Users.update({ _id: user._id }, { $unset: { 'settings.preferences.disableNewRoomNotification': 1, 'settings.preferences.disableNewMessageNotification': 1 }, $set: { 'settings.preferences.newRoomNotification': newRoomNotification, 'settings.preferences.newMessageNotification': newMessageNotification } }); }); } - if (RocketChat && RocketChat.models && RocketChat.models.Settings) { - const optOut = RocketChat.models.Settings.findOne({ _id: 'Statistics_opt_out' }); + if (Settings) { + const optOut = Settings.findOne({ _id: 'Statistics_opt_out' }); if (optOut) { - RocketChat.models.Settings.remove({ _id: 'Statistics_opt_out' }); - RocketChat.models.Settings.upsert({ _id: 'Statistics_reporting' }, { + Settings.remove({ _id: 'Statistics_opt_out' }); + Settings.upsert({ _id: 'Statistics_reporting' }, { $set: { value: !optOut.value, i18nDescription: 'Statistics_reporting_Description', @@ -24,11 +27,11 @@ RocketChat.Migrations.add({ } } - if (RocketChat && RocketChat.models && RocketChat.models.Settings) { - const favoriteRooms = RocketChat.models.Settings.findOne({ _id: 'Disable_Favorite_Rooms' }); + if (Settings) { + const favoriteRooms = Settings.findOne({ _id: 'Disable_Favorite_Rooms' }); if (favoriteRooms) { - RocketChat.models.Settings.remove({ _id: 'Disable_Favorite_Rooms' }); - RocketChat.models.Settings.upsert({ _id: 'Favorite_Rooms' }, { + Settings.remove({ _id: 'Disable_Favorite_Rooms' }); + Settings.upsert({ _id: 'Favorite_Rooms' }, { $set: { value: !favoriteRooms.value, i18nDescription: 'Favorite_Rooms_Description', diff --git a/server/startup/migrations/v045.js b/server/startup/migrations/v045.js index 2be7c4ae3fe90..c43b9e837ef3f 100644 --- a/server/startup/migrations/v045.js +++ b/server/startup/migrations/v045.js @@ -1,14 +1,18 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users } from 'meteor/rocketchat:models'; +import { settings } from 'meteor/rocketchat:settings'; + +Migrations.add({ version: 45, up() { // finds the latest created visitor - const lastVisitor = RocketChat.models.Users.find({ type: 'visitor' }, { fields: { username: 1 }, sort: { createdAt: -1 }, limit: 1 }).fetch(); + const lastVisitor = Users.find({ type: 'visitor' }, { fields: { username: 1 }, sort: { createdAt: -1 }, limit: 1 }).fetch(); if (lastVisitor && lastVisitor.length > 0) { const lastNumber = lastVisitor[0].username.replace(/^guest\-/, ''); - RocketChat.settings.add('Livechat_guest_count', (parseInt(lastNumber) + 1), { type: 'int', group: 'Livechat' }); + settings.add('Livechat_guest_count', (parseInt(lastNumber) + 1), { type: 'int', group: 'Livechat' }); } }, }); diff --git a/server/startup/migrations/v046.js b/server/startup/migrations/v046.js index 3d171be15ae06..ea167add41c1c 100644 --- a/server/startup/migrations/v046.js +++ b/server/startup/migrations/v046.js @@ -1,8 +1,11 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 46, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Users) { - RocketChat.models.Users.update({ type: { $exists: false } }, { $set: { type: 'user' } }, { multi: true }); + if (Users) { + Users.update({ type: { $exists: false } }, { $set: { type: 'user' } }, { multi: true }); } }, }); diff --git a/server/startup/migrations/v047.js b/server/startup/migrations/v047.js index 2ecbe80c79438..082068c4503b6 100644 --- a/server/startup/migrations/v047.js +++ b/server/startup/migrations/v047.js @@ -1,23 +1,26 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 47, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Settings) { - const autolinkerUrls = RocketChat.models.Settings.findOne({ _id: 'AutoLinker_Urls' }); + if (Settings) { + const autolinkerUrls = Settings.findOne({ _id: 'AutoLinker_Urls' }); if (autolinkerUrls) { - RocketChat.models.Settings.remove({ _id: 'AutoLinker_Urls' }); - RocketChat.models.Settings.upsert({ _id: 'AutoLinker_Urls_Scheme' }, { + Settings.remove({ _id: 'AutoLinker_Urls' }); + Settings.upsert({ _id: 'AutoLinker_Urls_Scheme' }, { $set: { value: !!autolinkerUrls.value, i18nLabel: 'AutoLinker_Urls_Scheme', }, }); - RocketChat.models.Settings.upsert({ _id: 'AutoLinker_Urls_www' }, { + Settings.upsert({ _id: 'AutoLinker_Urls_www' }, { $set: { value: !!autolinkerUrls.value, i18nLabel: 'AutoLinker_Urls_www', }, }); - RocketChat.models.Settings.upsert({ _id: 'AutoLinker_Urls_TLD' }, { + Settings.upsert({ _id: 'AutoLinker_Urls_TLD' }, { $set: { value: !!autolinkerUrls.value, i18nLabel: 'AutoLinker_Urls_TLD', diff --git a/server/startup/migrations/v048.js b/server/startup/migrations/v048.js index 731f38ef08868..cce3861e58267 100644 --- a/server/startup/migrations/v048.js +++ b/server/startup/migrations/v048.js @@ -1,16 +1,19 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 48, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Settings) { + if (Settings) { - const RocketBot_Enabled = RocketChat.models.Settings.findOne({ + const RocketBot_Enabled = Settings.findOne({ _id: 'RocketBot_Enabled', }); if (RocketBot_Enabled) { - RocketChat.models.Settings.remove({ + Settings.remove({ _id: 'RocketBot_Enabled', }); - RocketChat.models.Settings.upsert({ + Settings.upsert({ _id: 'InternalHubot_Enabled', }, { $set: { @@ -19,14 +22,14 @@ RocketChat.Migrations.add({ }); } - const RocketBot_Name = RocketChat.models.Settings.findOne({ + const RocketBot_Name = Settings.findOne({ _id: 'RocketBot_Name', }); if (RocketBot_Name) { - RocketChat.models.Settings.remove({ + Settings.remove({ _id: 'RocketBot_Name', }); - RocketChat.models.Settings.upsert({ + Settings.upsert({ _id: 'InternalHubot_Username', }, { $set: { diff --git a/server/startup/migrations/v049.js b/server/startup/migrations/v049.js index 635ba13afb426..6bdb839bfd1be 100644 --- a/server/startup/migrations/v049.js +++ b/server/startup/migrations/v049.js @@ -1,16 +1,19 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Rooms, Subscriptions, Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 49, up() { let count = 1; - RocketChat.models.Rooms.find({ t: 'l' }, { sort: { ts: 1 }, fields: { _id: 1 } }).forEach(function(room) { - RocketChat.models.Rooms.update({ _id: room._id }, { $set: { code: count } }); - RocketChat.models.Subscriptions.update({ rid: room._id }, { $set: { code: count } }, { multi: true }); + Rooms.find({ t: 'l' }, { sort: { ts: 1 }, fields: { _id: 1 } }).forEach(function(room) { + Rooms.update({ _id: room._id }, { $set: { code: count } }); + Subscriptions.update({ rid: room._id }, { $set: { code: count } }, { multi: true }); count++; }); - RocketChat.models.Settings.upsert({ _id: 'Livechat_Room_Count' }, { + Settings.upsert({ _id: 'Livechat_Room_Count' }, { $set: { value: count, type: 'int', diff --git a/server/startup/migrations/v050.js b/server/startup/migrations/v050.js index 769ce1c1cddda..92bb06aa68fa4 100644 --- a/server/startup/migrations/v050.js +++ b/server/startup/migrations/v050.js @@ -1,7 +1,10 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Subscriptions } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 50, up() { - RocketChat.models.Subscriptions.tryDropIndex('u._id_1_name_1_t_1'); - RocketChat.models.Subscriptions.tryEnsureIndex({ 'u._id': 1, name: 1, t: 1 }); + Subscriptions.tryDropIndex('u._id_1_name_1_t_1'); + Subscriptions.tryEnsureIndex({ 'u._id': 1, name: 1, t: 1 }); }, }); diff --git a/server/startup/migrations/v051.js b/server/startup/migrations/v051.js index 5f1c4da7719b0..3c43c1d2ae4c0 100644 --- a/server/startup/migrations/v051.js +++ b/server/startup/migrations/v051.js @@ -1,16 +1,19 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users, Rooms, Subscriptions } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 51, up() { - RocketChat.models.Rooms.find({ t: 'l', 'v.token': { $exists: true }, label: { $exists: false } }).forEach(function(room) { - const user = RocketChat.models.Users.findOne({ 'profile.token': room.v.token }); + Rooms.find({ t: 'l', 'v.token': { $exists: true }, label: { $exists: false } }).forEach(function(room) { + const user = Users.findOne({ 'profile.token': room.v.token }); if (user) { - RocketChat.models.Rooms.update({ _id: room._id }, { + Rooms.update({ _id: room._id }, { $set: { label: user.name || user.username, 'v._id': user._id, }, }); - RocketChat.models.Subscriptions.update({ rid: room._id }, { + Subscriptions.update({ rid: room._id }, { $set: { name: user.name || user.username, }, diff --git a/server/startup/migrations/v052.js b/server/startup/migrations/v052.js index 477ed19085527..e1a30bd5941a9 100644 --- a/server/startup/migrations/v052.js +++ b/server/startup/migrations/v052.js @@ -1,6 +1,9 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 52, up() { - RocketChat.models.Users.update({ _id: 'rocket.cat' }, { $addToSet: { roles: 'bot' } }); + Users.update({ _id: 'rocket.cat' }, { $addToSet: { roles: 'bot' } }); }, }); diff --git a/server/startup/migrations/v053.js b/server/startup/migrations/v053.js index 78c6b10d606e9..39534a3580b33 100644 --- a/server/startup/migrations/v053.js +++ b/server/startup/migrations/v053.js @@ -1,13 +1,16 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 53, up() { - RocketChat.models.Settings.update({ _id: 'Email_Header', value: '' }, { + Settings.update({ _id: 'Email_Header', value: '' }, { $set: { value: '

[Site_Name]

', }, }); - RocketChat.models.Settings.update({ _id: 'Email_Footer', value: '' }, { + Settings.update({ _id: 'Email_Footer', value: '' }, { $set: { value: '
Powered by Rocket.Chat
', }, diff --git a/server/startup/migrations/v054.js b/server/startup/migrations/v054.js index 29a911f62b55b..a44b9db196423 100644 --- a/server/startup/migrations/v054.js +++ b/server/startup/migrations/v054.js @@ -1,10 +1,13 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 54, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Users) { + if (Users) { // Set default message viewMode to 'normal' or 'cozy' depending on the users' current settings and remove the field 'compactView' - RocketChat.models.Users.update({ 'settings.preferences.compactView': true }, { $set: { 'settings.preferences.viewMode': 1 }, $unset: { 'settings.preferences.compactView': 1 } }, { multi: true }); - RocketChat.models.Users.update({ 'settings.preferences.viewMode': { $ne: 1 } }, { $set: { 'settings.preferences.viewMode': 0 } }, { multi: true }); + Users.update({ 'settings.preferences.compactView': true }, { $set: { 'settings.preferences.viewMode': 1 }, $unset: { 'settings.preferences.compactView': 1 } }, { multi: true }); + Users.update({ 'settings.preferences.viewMode': { $ne: 1 } }, { $set: { 'settings.preferences.viewMode': 0 } }, { multi: true }); } }, }); diff --git a/server/startup/migrations/v055.js b/server/startup/migrations/v055.js index 1e8cd34ed7181..6e840d7671180 100644 --- a/server/startup/migrations/v055.js +++ b/server/startup/migrations/v055.js @@ -1,12 +1,14 @@ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Rooms, Messages } from 'meteor/rocketchat:models'; import s from 'underscore.string'; -RocketChat.Migrations.add({ +Migrations.add({ version: 55, up() { - RocketChat.models.Rooms.find({ topic: { $exists: 1, $ne: '' } }, { topic: 1 }).forEach(function(room) { + Rooms.find({ topic: { $exists: 1, $ne: '' } }, { topic: 1 }).forEach(function(room) { const topic = s.escapeHTML(room.topic); - RocketChat.models.Rooms.update({ _id: room._id }, { $set: { topic } }); - RocketChat.models.Messages.update({ t: 'room_changed_topic', rid: room._id }, { $set: { msg: topic } }); + Rooms.update({ _id: room._id }, { $set: { topic } }); + Messages.update({ t: 'room_changed_topic', rid: room._id }, { $set: { msg: topic } }); }); }, }); diff --git a/server/startup/migrations/v056.js b/server/startup/migrations/v056.js index 174498b503af3..507f7ddf0f0ef 100644 --- a/server/startup/migrations/v056.js +++ b/server/startup/migrations/v056.js @@ -1,11 +1,14 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Messages } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 56, up() { - RocketChat.models.Messages.find({ _id: /\./ }).forEach(function(message) { + Messages.find({ _id: /\./ }).forEach(function(message) { const oldId = message._id; message._id = message._id.replace(/(.*)\.S?(.*)/, 'slack-$1-$2'); - RocketChat.models.Messages.insert(message); - RocketChat.models.Messages.remove({ _id: oldId }); + Messages.insert(message); + Messages.remove({ _id: oldId }); }); }, }); diff --git a/server/startup/migrations/v057.js b/server/startup/migrations/v057.js index 0f80972aed781..c2a070becbf74 100644 --- a/server/startup/migrations/v057.js +++ b/server/startup/migrations/v057.js @@ -1,27 +1,30 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Messages } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 57, up() { - RocketChat.models.Messages.find({ _id: /slack-([a-zA-Z0-9]+)S([0-9]+-[0-9]+)/ }).forEach(function(message) { + Messages.find({ _id: /slack-([a-zA-Z0-9]+)S([0-9]+-[0-9]+)/ }).forEach(function(message) { const oldId = message._id; message._id = message._id.replace(/slack-([a-zA-Z0-9]+)S([0-9]+-[0-9]+)/, 'slack-$1-$2'); - RocketChat.models.Messages.insert(message); - RocketChat.models.Messages.remove({ _id: oldId }); + Messages.insert(message); + Messages.remove({ _id: oldId }); }); - RocketChat.models.Messages.find({ _id: /slack-slack/ }).forEach(function(message) { + Messages.find({ _id: /slack-slack/ }).forEach(function(message) { const oldId = message._id; message._id = message._id.replace('slack-slack', 'slack'); - RocketChat.models.Messages.insert(message); - RocketChat.models.Messages.remove({ _id: oldId }); + Messages.insert(message); + Messages.remove({ _id: oldId }); }); - RocketChat.models.Messages.find({ _id: /\./ }).forEach(function(message) { + Messages.find({ _id: /\./ }).forEach(function(message) { const oldId = message._id; message._id = message._id.replace(/(.*)\.?S(.*)/, 'slack-$1-$2'); message._id = message._id.replace(/\./g, '-'); - RocketChat.models.Messages.remove({ _id: message._id }); - RocketChat.models.Messages.insert(message); - RocketChat.models.Messages.remove({ _id: oldId }); + Messages.remove({ _id: message._id }); + Messages.insert(message); + Messages.remove({ _id: oldId }); }); }, }); diff --git a/server/startup/migrations/v058.js b/server/startup/migrations/v058.js index bcee11484db03..ec7924da5a0f9 100644 --- a/server/startup/migrations/v058.js +++ b/server/startup/migrations/v058.js @@ -1,7 +1,10 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 58, up() { - RocketChat.models.Settings.update({ _id: 'Push_gateway', value: 'https://rocket.chat' }, { + Settings.update({ _id: 'Push_gateway', value: 'https://rocket.chat' }, { $set: { value: 'https://gateway.rocket.chat', packageValue: 'https://gateway.rocket.chat', diff --git a/server/startup/migrations/v059.js b/server/startup/migrations/v059.js index 9e8a0bdcd4588..9340604f2dc8f 100644 --- a/server/startup/migrations/v059.js +++ b/server/startup/migrations/v059.js @@ -1,12 +1,13 @@ -import { Statistics } from 'meteor/rocketchat:models'; +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users, Settings, Statistics } from 'meteor/rocketchat:models'; -RocketChat.Migrations.add({ +Migrations.add({ version: 59, up() { - const users = RocketChat.models.Users.find({}, { sort: { createdAt: 1 }, limit: 1 }).fetch(); + const users = Users.find({}, { sort: { createdAt: 1 }, limit: 1 }).fetch(); if (users && users.length > 0) { const { createdAt } = users[0]; - RocketChat.models.Settings.update({ createdAt: { $exists: 0 } }, { $set: { createdAt } }, { multi: true }); + Settings.update({ createdAt: { $exists: 0 } }, { $set: { createdAt } }, { multi: true }); Statistics.update({ installedAt: { $exists: 0 } }, { $set: { installedAt: createdAt } }, { multi: true }); } }, diff --git a/server/startup/migrations/v060.js b/server/startup/migrations/v060.js index d5d3460a98fc9..30c3b1ac77d23 100644 --- a/server/startup/migrations/v060.js +++ b/server/startup/migrations/v060.js @@ -1,17 +1,19 @@ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users, Subscriptions } from 'meteor/rocketchat:models'; import _ from 'underscore'; -RocketChat.Migrations.add({ +Migrations.add({ version: 60, up() { - let subscriptions = RocketChat.models.Subscriptions.find({ $or: [{ name: { $exists: 0 } }, { name: { $not: { $type: 2 } } }] }).fetch(); + let subscriptions = Subscriptions.find({ $or: [{ name: { $exists: 0 } }, { name: { $not: { $type: 2 } } }] }).fetch(); if (subscriptions && subscriptions.length > 0) { - RocketChat.models.Subscriptions.remove({ _id: { $in: _.pluck(subscriptions, '_id') } }); + Subscriptions.remove({ _id: { $in: _.pluck(subscriptions, '_id') } }); } - subscriptions = RocketChat.models.Subscriptions.find().forEach(function(subscription) { - const user = RocketChat.models.Users.findOne({ _id: subscription && subscription.u && subscription.u._id }); + subscriptions = Subscriptions.find().forEach(function(subscription) { + const user = Users.findOne({ _id: subscription && subscription.u && subscription.u._id }); if (!user) { - RocketChat.models.Subscriptions.remove({ _id: subscription._id }); + Subscriptions.remove({ _id: subscription._id }); } }); }, diff --git a/server/startup/migrations/v061.js b/server/startup/migrations/v061.js index 5f7cae3b2da1f..b39f2e20b14da 100644 --- a/server/startup/migrations/v061.js +++ b/server/startup/migrations/v061.js @@ -1,8 +1,11 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users, Subscriptions } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 61, up() { - RocketChat.models.Users.find({ active: false }).forEach(function(user) { - RocketChat.models.Subscriptions.setArchivedByUsername(user.username, true); + Users.find({ active: false }).forEach(function(user) { + Subscriptions.setArchivedByUsername(user.username, true); }); }, }); diff --git a/server/startup/migrations/v062.js b/server/startup/migrations/v062.js index 32699b65b5523..83a35ad40b8c8 100644 --- a/server/startup/migrations/v062.js +++ b/server/startup/migrations/v062.js @@ -1,6 +1,9 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 62, up() { - RocketChat.models.Settings.remove({ _id: 'Atlassian Crowd', type: 'group' }); + Settings.remove({ _id: 'Atlassian Crowd', type: 'group' }); }, }); diff --git a/server/startup/migrations/v063.js b/server/startup/migrations/v063.js index c2a3efca6a155..66e56986c70b7 100644 --- a/server/startup/migrations/v063.js +++ b/server/startup/migrations/v063.js @@ -1,11 +1,14 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 63, up() { - const forward = RocketChat.models.Settings.findOne({ _id:'Livechat_forward_open_chats' }); - const timeout = RocketChat.models.Settings.findOne({ _id:'Livechat_forward_open_chats_timeout' }); + const forward = Settings.findOne({ _id:'Livechat_forward_open_chats' }); + const timeout = Settings.findOne({ _id:'Livechat_forward_open_chats_timeout' }); if (forward && forward.value) { - RocketChat.models.Settings.upsert({ _id: 'Livechat_agent_leave_action' }, { + Settings.upsert({ _id: 'Livechat_agent_leave_action' }, { $set: { value: 'forward', type: 'string', @@ -15,7 +18,7 @@ RocketChat.Migrations.add({ } if (timeout && timeout.value !== 60) { - RocketChat.models.Settings.upsert({ _id: 'Livechat_agent_leave_action_timeout' }, { + Settings.upsert({ _id: 'Livechat_agent_leave_action_timeout' }, { $set: { value: timeout.value, type: 'int', @@ -24,7 +27,7 @@ RocketChat.Migrations.add({ }); } - RocketChat.models.Settings.remove({ _id: 'Livechat_forward_open_chats' }); - RocketChat.models.Settings.remove({ _id: 'Livechat_forward_open_chats_timeout' }); + Settings.remove({ _id: 'Livechat_forward_open_chats' }); + Settings.remove({ _id: 'Livechat_forward_open_chats_timeout' }); }, }); diff --git a/server/startup/migrations/v064.js b/server/startup/migrations/v064.js index 84445248e82e0..84ece66ae7fd8 100644 --- a/server/startup/migrations/v064.js +++ b/server/startup/migrations/v064.js @@ -1,11 +1,13 @@ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Messages } from 'meteor/rocketchat:models'; import s from 'underscore.string'; -RocketChat.Migrations.add({ +Migrations.add({ version: 64, up() { - RocketChat.models.Messages.find({ t: 'room_changed_topic', msg: / { - RocketChat.models.Settings.remove({ _id: setting._id }); + if (Settings) { + Settings.find({ section: 'Colors (alphas)' }).forEach((setting) => { + Settings.remove({ _id: setting._id }); }); } }, diff --git a/server/startup/migrations/v077.js b/server/startup/migrations/v077.js index 975b91c8452e9..49ab36f4924e8 100644 --- a/server/startup/migrations/v077.js +++ b/server/startup/migrations/v077.js @@ -1,16 +1,19 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Rooms, Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 77, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Rooms) { - RocketChat.models.Rooms.find({ + if (Rooms) { + Rooms.find({ t: 'l', 'v._id': { $exists: true }, 'v.username': { $exists: false }, }, { fields: { 'v._id': 1 } }).forEach(function(room) { - const user = RocketChat.models.Users.findOne({ _id: room.v._id }, { username: 1 }); + const user = Users.findOne({ _id: room.v._id }, { username: 1 }); if (user && user.username) { - RocketChat.models.Rooms.update({ + Rooms.update({ _id: room._id, }, { $set: { diff --git a/server/startup/migrations/v078.js b/server/startup/migrations/v078.js index 0fed3e168a3b0..bd697c8259889 100644 --- a/server/startup/migrations/v078.js +++ b/server/startup/migrations/v078.js @@ -1,6 +1,9 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Permissions } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 78, up() { - RocketChat.models.Permissions.update({ _id: { $in: ['create-c', 'create-d', 'create-p'] } }, { $addToSet: { roles: 'bot' } }, { multi: true }); + Permissions.update({ _id: { $in: ['create-c', 'create-d', 'create-p'] } }, { $addToSet: { roles: 'bot' } }, { multi: true }); }, }); diff --git a/server/startup/migrations/v079.js b/server/startup/migrations/v079.js index 4b508f1f51fef..ccfa5769dcfd3 100644 --- a/server/startup/migrations/v079.js +++ b/server/startup/migrations/v079.js @@ -1,11 +1,14 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Integrations } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 79, up() { - const integrations = RocketChat.models.Integrations.find({ type: 'webhook-incoming' }).fetch(); + const integrations = Integrations.find({ type: 'webhook-incoming' }).fetch(); for (const integration of integrations) { if (typeof integration.channel === 'string') { - RocketChat.models.Integrations.update({ _id: integration._id }, { + Integrations.update({ _id: integration._id }, { $set: { channel: integration.channel.split(',').map((channel) => channel.trim()), }, diff --git a/server/startup/migrations/v080.js b/server/startup/migrations/v080.js index 7852347a92a4e..d07fd736951bb 100644 --- a/server/startup/migrations/v080.js +++ b/server/startup/migrations/v080.js @@ -1,4 +1,7 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Integrations } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 80, up() { const query = { @@ -20,6 +23,6 @@ RocketChat.Migrations.add({ }, }; - RocketChat.models.Integrations.update(query, update, { multi: true }); + Integrations.update(query, update, { multi: true }); }, }); diff --git a/server/startup/migrations/v081.js b/server/startup/migrations/v081.js index 6d28b18327510..8e16dab0e11f8 100644 --- a/server/startup/migrations/v081.js +++ b/server/startup/migrations/v081.js @@ -1,7 +1,10 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { OAuthApps } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 81, up() { - RocketChat.models.OAuthApps.update({ _id: 'zapier' }, { + OAuthApps.update({ _id: 'zapier' }, { $set: { active: true, redirectUri: 'https://zapier.com/dashboard/auth/oauth/return/App32270API/', diff --git a/server/startup/migrations/v082.js b/server/startup/migrations/v082.js index e58cf19a84773..115e1d85943e5 100644 --- a/server/startup/migrations/v082.js +++ b/server/startup/migrations/v082.js @@ -1,9 +1,12 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { getUsersInRole, removeUserFromRoles } from 'meteor/rocketchat:authorization'; + +Migrations.add({ version: 82, up() { - const admins = RocketChat.authz.getUsersInRole('admin').fetch(); + const admins = getUsersInRole('admin').fetch(); if (admins.length === 1 && admins[0]._id === 'rocket.cat') { - RocketChat.authz.removeUserFromRoles('rocket.cat', 'admin'); + removeUserFromRoles('rocket.cat', 'admin'); } }, }); diff --git a/server/startup/migrations/v083.js b/server/startup/migrations/v083.js index 97276b1e94e0f..31d1e3ba7b78a 100644 --- a/server/startup/migrations/v083.js +++ b/server/startup/migrations/v083.js @@ -1,13 +1,16 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings, Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 83, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Settings && RocketChat.models.Users) { - const setting = RocketChat.models.Settings.findOne({ _id: 'InternalHubot_Username' }); + if (Settings && Users) { + const setting = Settings.findOne({ _id: 'InternalHubot_Username' }); if (setting && setting.value) { const username = setting.value; - const user = RocketChat.models.Users.findOne({ username }); + const user = Users.findOne({ username }); if (!user && setting.value === 'Rocket.Cat') { - RocketChat.models.Settings.update({ _id: 'InternalHubot_Username' }, { $set: { value: 'rocket.cat', packageValue: 'rocket.cat' } }); + Settings.update({ _id: 'InternalHubot_Username' }, { $set: { value: 'rocket.cat', packageValue: 'rocket.cat' } }); } } } diff --git a/server/startup/migrations/v084.js b/server/startup/migrations/v084.js index 9b8cfb2a3b66b..7816788bb8f72 100644 --- a/server/startup/migrations/v084.js +++ b/server/startup/migrations/v084.js @@ -1,25 +1,28 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Permissions } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 84, up() { - if (RocketChat.models && RocketChat.models.Permissions) { + if (Permissions) { // Update permission name, copy values from old name - const oldPermission = RocketChat.models.Permissions.findOne('add-user-to-room'); + const oldPermission = Permissions.findOne('add-user-to-room'); if (oldPermission && oldPermission.roles.length) { - RocketChat.models.Permissions.upsert({ _id: 'add-user-to-joined-room' }, { $set: { roles: oldPermission.roles } }); - RocketChat.models.Permissions.remove({ _id: 'add-user-to-room' }); + Permissions.upsert({ _id: 'add-user-to-joined-room' }, { $set: { roles: oldPermission.roles } }); + Permissions.remove({ _id: 'add-user-to-room' }); } } }, down() { - if (RocketChat.models && RocketChat.models.Permissions) { + if (Permissions) { // Revert permission name, copy values from updated name - const newPermission = RocketChat.models.Permissions.findOne('add-user-to-joined-room'); + const newPermission = Permissions.findOne('add-user-to-joined-room'); if (newPermission && newPermission.roles.length) { - RocketChat.models.Permissions.upsert({ _id: 'add-user-to-room' }, { $set: { roles: newPermission.roles } }); - RocketChat.models.Permissions.remove({ _id: 'add-user-to-joined-room' }); + Permissions.upsert({ _id: 'add-user-to-room' }, { $set: { roles: newPermission.roles } }); + Permissions.remove({ _id: 'add-user-to-joined-room' }); } } }, diff --git a/server/startup/migrations/v085.js b/server/startup/migrations/v085.js index 0e08800ec3b17..aceb9491e514c 100644 --- a/server/startup/migrations/v085.js +++ b/server/startup/migrations/v085.js @@ -1,4 +1,7 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Rooms, Subscriptions } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 85, up() { const query = { @@ -8,12 +11,12 @@ RocketChat.Migrations.add({ name: { $exists: false }, }; - const rooms = RocketChat.models.Rooms.find(query).fetch(); + const rooms = Rooms.find(query).fetch(); if (rooms.length > 0) { const rids = rooms.map((room) => room._id); - RocketChat.models.Rooms.update({ _id: { $in: rids } }, { $set: { t: 'd' } }, { multi: true }); - RocketChat.models.Subscriptions.update({ rid: { $in: rids } }, { $set: { t: 'd' } }, { multi: true }); + Rooms.update({ _id: { $in: rids } }, { $set: { t: 'd' } }, { multi: true }); + Subscriptions.update({ rid: { $in: rids } }, { $set: { t: 'd' } }, { multi: true }); } }, }); diff --git a/server/startup/migrations/v086.js b/server/startup/migrations/v086.js index 785c05a705ea9..55c83a6be5a0e 100644 --- a/server/startup/migrations/v086.js +++ b/server/startup/migrations/v086.js @@ -1,4 +1,6 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; + +Migrations.add({ version: 86, up() { // Disabled this migration for it was not updating any user diff --git a/server/startup/migrations/v087.js b/server/startup/migrations/v087.js index c86ffc28c8fb6..3e2cd331928f8 100644 --- a/server/startup/migrations/v087.js +++ b/server/startup/migrations/v087.js @@ -1,11 +1,14 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 87, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Users) { - RocketChat.models.Users.update({ 'settings.preferences.newMessageNotification': false }, { $set: { 'settings.preferences.newMessageNotification': 'none' } }, { multi: true }); - RocketChat.models.Users.update({ 'settings.preferences.newMessageNotification': true }, { $unset: { 'settings.preferences.newMessageNotification': 1 } }, { multi: true }); - RocketChat.models.Users.update({ 'settings.preferences.newRoomNotification': false }, { $set: { 'settings.preferences.newRoomNotification': 'none' } }, { multi: true }); - RocketChat.models.Users.update({ 'settings.preferences.newRoomNotification': true }, { $unset: { 'settings.preferences.newRoomNotification': 1 } }, { multi: true }); + if (Users) { + Users.update({ 'settings.preferences.newMessageNotification': false }, { $set: { 'settings.preferences.newMessageNotification': 'none' } }, { multi: true }); + Users.update({ 'settings.preferences.newMessageNotification': true }, { $unset: { 'settings.preferences.newMessageNotification': 1 } }, { multi: true }); + Users.update({ 'settings.preferences.newRoomNotification': false }, { $set: { 'settings.preferences.newRoomNotification': 'none' } }, { multi: true }); + Users.update({ 'settings.preferences.newRoomNotification': true }, { $unset: { 'settings.preferences.newRoomNotification': 1 } }, { multi: true }); } }, }); diff --git a/server/startup/migrations/v088.js b/server/startup/migrations/v088.js index 6572d9e44feb2..d9e05108b68cc 100644 --- a/server/startup/migrations/v088.js +++ b/server/startup/migrations/v088.js @@ -1,11 +1,14 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 88, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Settings) { - const setting = RocketChat.models.Settings.findOne({ _id: 'Layout_Sidenav_Footer' }); + if (Settings) { + const setting = Settings.findOne({ _id: 'Layout_Sidenav_Footer' }); if (setting && setting.value && setting.packageValue) { if (setting.value === '') { - RocketChat.models.Settings.update({ _id: 'Layout_Sidenav_Footer' }, { $set: { value: setting.packageValue } }); + Settings.update({ _id: 'Layout_Sidenav_Footer' }, { $set: { value: setting.packageValue } }); } } } diff --git a/server/startup/migrations/v089.js b/server/startup/migrations/v089.js index 734d5fa7eb3ec..c90149dec8ea3 100644 --- a/server/startup/migrations/v089.js +++ b/server/startup/migrations/v089.js @@ -1,17 +1,20 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Integrations } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 89, up() { - const outgoingIntegrations = RocketChat.models.Integrations.find({ type: 'webhook-outgoing' }, { fields: { name: 1 } }).fetch(); + const outgoingIntegrations = Integrations.find({ type: 'webhook-outgoing' }, { fields: { name: 1 } }).fetch(); outgoingIntegrations.forEach((i) => { - RocketChat.models.Integrations.update(i._id, { $set: { event: 'sendMessage', retryFailedCalls: true, retryCount: 6, retryDelay: 'powers-of-ten' } }); + Integrations.update(i._id, { $set: { event: 'sendMessage', retryFailedCalls: true, retryCount: 6, retryDelay: 'powers-of-ten' } }); }); }, down() { - const outgoingIntegrations = RocketChat.models.Integrations.find({ type: 'webhook-outgoing', event: { $ne: 'sendMessage' } }, { fields: { name: 1 } }).fetch(); + const outgoingIntegrations = Integrations.find({ type: 'webhook-outgoing', event: { $ne: 'sendMessage' } }, { fields: { name: 1 } }).fetch(); outgoingIntegrations.forEach((i) => { - RocketChat.models.Integrations.update(i._id, { $set: { enabled: false } }); + Integrations.update(i._id, { $set: { enabled: false } }); }); }, }); diff --git a/server/startup/migrations/v090.js b/server/startup/migrations/v090.js index 39dff7036880f..aacda8164bcc9 100644 --- a/server/startup/migrations/v090.js +++ b/server/startup/migrations/v090.js @@ -1,12 +1,15 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 90, up() { - RocketChat.models.Settings.remove({ _id: 'Piwik', type: 'group' }); + Settings.remove({ _id: 'Piwik', type: 'group' }); - const settings = RocketChat.models.Settings.find({ $or: [{ _id: 'PiwikAnalytics_url', value: { $ne: null } }, { _id: 'PiwikAnalytics_siteId', value: { $ne: null } }] }).fetch(); + const settings = Settings.find({ $or: [{ _id: 'PiwikAnalytics_url', value: { $ne: null } }, { _id: 'PiwikAnalytics_siteId', value: { $ne: null } }] }).fetch(); if (settings && settings.length === 2) { - RocketChat.models.Settings.upsert({ _id: 'PiwikAnalytics_enabled' }, { $set: { value: true } }); + Settings.upsert({ _id: 'PiwikAnalytics_enabled' }, { $set: { value: true } }); } }, }); diff --git a/server/startup/migrations/v091.js b/server/startup/migrations/v091.js index 527025219f258..79ef860b5f6fb 100644 --- a/server/startup/migrations/v091.js +++ b/server/startup/migrations/v091.js @@ -1,4 +1,7 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 91, up() { const query = { @@ -14,10 +17,10 @@ RocketChat.Migrations.add({ }], }; - RocketChat.models.Users.find(query, { 'services.linkedin.firstName': 1, username: 1 }).forEach((user) => { + Users.find(query, { 'services.linkedin.firstName': 1, username: 1 }).forEach((user) => { const name = `${ user.services.linkedin.firstName } ${ user.services.linkedin.lastName }`; - RocketChat.models.Users.setName(user._id, name); + Users.setName(user._id, name); }); }, }); diff --git a/server/startup/migrations/v092.js b/server/startup/migrations/v092.js index 076301d5c139c..8254b3cc7553c 100644 --- a/server/startup/migrations/v092.js +++ b/server/startup/migrations/v092.js @@ -1,10 +1,13 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Integrations } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 92, up() { - const outgoingIntegrations = RocketChat.models.Integrations.find({ type: 'webhook-outgoing', event: 'sendMessage' }, { fields: { name: 1 } }).fetch(); + const outgoingIntegrations = Integrations.find({ type: 'webhook-outgoing', event: 'sendMessage' }, { fields: { name: 1 } }).fetch(); outgoingIntegrations.forEach((i) => { - RocketChat.models.Integrations.update(i._id, { $set: { runOnEdits: true } }); + Integrations.update(i._id, { $set: { runOnEdits: true } }); }); }, }); diff --git a/server/startup/migrations/v093.js b/server/startup/migrations/v093.js index 0ac1f2dfb4a00..705982e25451e 100644 --- a/server/startup/migrations/v093.js +++ b/server/startup/migrations/v093.js @@ -1,11 +1,14 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings, Permissions } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 93, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Settings) { - const setting = RocketChat.models.Settings.findOne({ _id: 'Accounts_AllowAnonymousAccess' }); + if (Settings) { + const setting = Settings.findOne({ _id: 'Accounts_AllowAnonymousAccess' }); if (setting && setting.value === true) { - RocketChat.models.Settings.update({ _id: 'Accounts_AllowAnonymousRead' }, { $set: { value: setting.value } }); + Settings.update({ _id: 'Accounts_AllowAnonymousRead' }, { $set: { value: setting.value } }); } } @@ -27,6 +30,6 @@ RocketChat.Migrations.add({ }, }; - RocketChat.models.Permissions.update(query, update, { multi: true }); + Permissions.update(query, update, { multi: true }); }, }); diff --git a/server/startup/migrations/v094.js b/server/startup/migrations/v094.js index cdf69fb0c430c..154180fa45ecd 100644 --- a/server/startup/migrations/v094.js +++ b/server/startup/migrations/v094.js @@ -1,11 +1,14 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 94, up() { const query = { 'emails.address.address': { $exists: true }, }; - RocketChat.models.Users.find(query, { 'emails.address.address': 1 }).forEach((user) => { + Users.find(query, { 'emails.address.address': 1 }).forEach((user) => { let emailAddress; user.emails.some((email) => { if (email.address && email.address.address) { @@ -14,9 +17,9 @@ RocketChat.Migrations.add({ } return false; }); - const existingUser = RocketChat.models.Users.findOne({ 'emails.address': emailAddress }, { fields: { _id: 1 } }); + const existingUser = Users.findOne({ 'emails.address': emailAddress }, { fields: { _id: 1 } }); if (existingUser) { - RocketChat.models.Users.update({ + Users.update({ _id: user._id, 'emails.address.address': emailAddress, }, { @@ -25,7 +28,7 @@ RocketChat.Migrations.add({ }, }); } else { - RocketChat.models.Users.update({ + Users.update({ _id: user._id, 'emails.address.address': emailAddress, }, { diff --git a/server/startup/migrations/v095.js b/server/startup/migrations/v095.js index 4db693db67c6a..afe394cca335d 100644 --- a/server/startup/migrations/v095.js +++ b/server/startup/migrations/v095.js @@ -1,21 +1,24 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 95, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Settings) { - const emailHeader = RocketChat.models.Settings.findOne({ _id: 'Email_Header' }); - const emailFooter = RocketChat.models.Settings.findOne({ _id: 'Email_Footer' }); + if (Settings) { + const emailHeader = Settings.findOne({ _id: 'Email_Header' }); + const emailFooter = Settings.findOne({ _id: 'Email_Footer' }); const startWithHTML = emailHeader.value.match(/^/); const endsWithHTML = emailFooter.value.match(/<\/html>$/); if (!startWithHTML) { - RocketChat.models.Settings.update( + Settings.update( { _id: 'Email_Header' }, { $set: { value: `${ emailHeader.value }` } } ); } if (!endsWithHTML) { - RocketChat.models.Settings.update( + Settings.update( { _id: 'Email_Footer' }, { $set: { value: `${ emailFooter.value }` } } ); diff --git a/server/startup/migrations/v096.js b/server/startup/migrations/v096.js index 6aabddf16938c..ce82392c634e2 100644 --- a/server/startup/migrations/v096.js +++ b/server/startup/migrations/v096.js @@ -1,8 +1,11 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 96, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Settings) { - RocketChat.models.Settings.update({ _id: 'InternalHubot_ScriptsToLoad' }, { $set: { value: '' } }); + if (Settings) { + Settings.update({ _id: 'InternalHubot_ScriptsToLoad' }, { $set: { value: '' } }); } }, }); diff --git a/server/startup/migrations/v097.js b/server/startup/migrations/v097.js index 919d0ae527ae5..0c9e068fc84b5 100644 --- a/server/startup/migrations/v097.js +++ b/server/startup/migrations/v097.js @@ -1,4 +1,6 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; + +Migrations.add({ version: 97, up() { // Migration moved to 099.js to fix a bug diff --git a/server/startup/migrations/v098.js b/server/startup/migrations/v098.js index 211ff2c629d3a..67f567d4df840 100644 --- a/server/startup/migrations/v098.js +++ b/server/startup/migrations/v098.js @@ -1,7 +1,10 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { OAuthApps } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 98, up() { - RocketChat.models.OAuthApps.update({ _id: 'zapier' }, { + OAuthApps.update({ _id: 'zapier' }, { $set: { redirectUri: 'https://zapier.com/dashboard/auth/oauth/return/RocketChatDevAPI/', }, diff --git a/server/startup/migrations/v099.js b/server/startup/migrations/v099.js index 5dd774991c82e..bf3a0fc862a38 100644 --- a/server/startup/migrations/v099.js +++ b/server/startup/migrations/v099.js @@ -4,6 +4,8 @@ import { Mongo } from 'meteor/mongo'; import { RocketChatFile } from 'meteor/rocketchat:file'; import { SystemLogger } from 'meteor/rocketchat:logger'; import { FileUpload } from 'meteor/rocketchat:file-upload'; +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Uploads, Settings, Users } from 'meteor/rocketchat:models'; import fs from 'fs'; import path from 'path'; @@ -42,7 +44,7 @@ function batch(arr, limit, fn) { return Promise.all(arr.splice(0, limit).map((item) => fn(item))).then(() => batch(arr, limit, fn)); } -RocketChat.Migrations.add({ +Migrations.add({ version: 99, up() { log('Migrating avatars. This might take a while.'); @@ -59,9 +61,9 @@ RocketChat.Migrations.add({ }], }; - RocketChat.models.Uploads.find(query).forEach((record) => { + Uploads.find(query).forEach((record) => { if (record.s3) { - RocketChat.models.Uploads.model.direct.update({ _id: record._id }, { + Uploads.model.direct.update({ _id: record._id }, { $set: { store: 'AmazonS3:Uploads', AmazonS3: { @@ -73,7 +75,7 @@ RocketChat.Migrations.add({ }, }, { multi: true }); } else { - RocketChat.models.Uploads.model.direct.update({ _id: record._id }, { + Uploads.model.direct.update({ _id: record._id }, { $set: { store: 'GoogleCloudStorage:Uploads', GoogleStorage: { @@ -87,7 +89,7 @@ RocketChat.Migrations.add({ } }); - RocketChat.models.Uploads.model.direct.update({ + Uploads.model.direct.update({ store: 'fileSystem', }, { $set: { @@ -96,7 +98,7 @@ RocketChat.Migrations.add({ }, { multi: true, }); - RocketChat.models.Uploads.model.direct.update({ + Uploads.model.direct.update({ store: 'rocketchat_uploads', }, { $set: { @@ -118,8 +120,8 @@ RocketChat.Migrations.add({ 'linkedin', ]; - const avatarsPathRecord = RocketChat.models.Settings.findOne({ _id: 'Accounts_AvatarStorePath' }); - const avatarStoreTypeRecord = RocketChat.models.Settings.findOne({ _id: 'Accounts_AvatarStoreType' }); + const avatarsPathRecord = Settings.findOne({ _id: 'Accounts_AvatarStorePath' }); + const avatarStoreTypeRecord = Settings.findOne({ _id: 'Accounts_AvatarStoreType' }); const avatarsPath = avatarsPathRecord ? avatarsPathRecord.value : process.env.AVATARS_PATH; let avatarStoreType = avatarStoreTypeRecord && avatarStoreTypeRecord.value; @@ -144,7 +146,7 @@ RocketChat.Migrations.add({ Meteor.setTimeout(function() { const avatarsFileStore = FileUpload.getStore('Avatars'); - const users = RocketChat.models.Users.find({ avatarOrigin: { $in: avatarOrigins } }, { avatarOrigin: 1, username: 1 }).fetch(); + const users = Users.find({ avatarOrigin: { $in: avatarOrigins } }, { avatarOrigin: 1, username: 1 }).fetch(); const usersTotal = users.length; @@ -208,8 +210,8 @@ RocketChat.Migrations.add({ } catch (error) { console.warn('Migration Error: avatars.files and avatars.chunks collections may not exist!'); } - RocketChat.models.Settings.remove({ _id: 'Accounts_AvatarStoreType' }); - RocketChat.models.Settings.remove({ _id: 'Accounts_AvatarStorePath' }); + Settings.remove({ _id: 'Accounts_AvatarStoreType' }); + Settings.remove({ _id: 'Accounts_AvatarStorePath' }); }).catch((error) => console.error(error)); }, 1000); }); diff --git a/server/startup/migrations/v100.js b/server/startup/migrations/v100.js index b33e9b637aee4..fd7c0d66d0091 100644 --- a/server/startup/migrations/v100.js +++ b/server/startup/migrations/v100.js @@ -1,6 +1,9 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Subscriptions } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 100, up() { - RocketChat.models.Subscriptions.update({ audioNotification:{ $exists:1 } }, { $rename: { audioNotification: 'audioNotifications' } }); + Subscriptions.update({ audioNotification:{ $exists:1 } }, { $rename: { audioNotification: 'audioNotifications' } }); }, }); diff --git a/server/startup/migrations/v101.js b/server/startup/migrations/v101.js index 8651de2fb4c97..1e077f2fa4e7d 100644 --- a/server/startup/migrations/v101.js +++ b/server/startup/migrations/v101.js @@ -1,6 +1,9 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Subscriptions } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 101, up() { - RocketChat.models.Subscriptions.update({ lastActivity:{ $exists:1 } }, { $unset: { lastActivity: '' } }, { multi: true }); + Subscriptions.update({ lastActivity:{ $exists:1 } }, { $unset: { lastActivity: '' } }, { multi: true }); }, }); diff --git a/server/startup/migrations/v102.js b/server/startup/migrations/v102.js index 20e6d19a9bc6f..b1acb15d57d40 100644 --- a/server/startup/migrations/v102.js +++ b/server/startup/migrations/v102.js @@ -1,47 +1,50 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 102, up() { - if (!RocketChat || !RocketChat.models || !RocketChat.models.Settings) { + if (!Settings) { return; } - RocketChat.models.Settings.update( + Settings.update( { _id: 'LDAP_Connect_Timeout', value: 600000 }, { $set: { value: 1000 } } ); - RocketChat.models.Settings.update( + Settings.update( { _id: 'LDAP_Idle_Timeout', value: 600000 }, { $set: { value: 1000 } } ); - const LDAP_Domain_Base = RocketChat.models.Settings.findOne({ _id: 'LDAP_Domain_Base' }); + const LDAP_Domain_Base = Settings.findOne({ _id: 'LDAP_Domain_Base' }); if (LDAP_Domain_Base) { - RocketChat.models.Settings.update( + Settings.update( { _id: 'LDAP_BaseDN' }, { $set: { value: LDAP_Domain_Base.value } } ); } - RocketChat.models.Settings.remove({ _id: 'LDAP_Domain_Base' }); + Settings.remove({ _id: 'LDAP_Domain_Base' }); - const LDAP_Domain_Search_User_ID = RocketChat.models.Settings.findOne({ _id: 'LDAP_Domain_Search_User_ID' }); + const LDAP_Domain_Search_User_ID = Settings.findOne({ _id: 'LDAP_Domain_Search_User_ID' }); if (LDAP_Domain_Search_User_ID) { - RocketChat.models.Settings.update( + Settings.update( { _id: 'LDAP_User_Search_Field' }, { $set: { value: LDAP_Domain_Search_User_ID.value } } ); } - RocketChat.models.Settings.remove({ _id: 'LDAP_Domain_Search_User_ID' }); + Settings.remove({ _id: 'LDAP_Domain_Search_User_ID' }); - const LDAP_Use_Custom_Domain_Search = RocketChat.models.Settings.findOne({ _id: 'LDAP_Use_Custom_Domain_Search' }); - const LDAP_Custom_Domain_Search = RocketChat.models.Settings.findOne({ _id: 'LDAP_Custom_Domain_Search' }); + const LDAP_Use_Custom_Domain_Search = Settings.findOne({ _id: 'LDAP_Use_Custom_Domain_Search' }); + const LDAP_Custom_Domain_Search = Settings.findOne({ _id: 'LDAP_Custom_Domain_Search' }); - const LDAP_Domain_Search_User = RocketChat.models.Settings.findOne({ _id: 'LDAP_Domain_Search_User' }); - const LDAP_Domain_Search_Password = RocketChat.models.Settings.findOne({ _id: 'LDAP_Domain_Search_Password' }); - const LDAP_Domain_Search_Filter = RocketChat.models.Settings.findOne({ _id: 'LDAP_Domain_Search_Filter' }); + const LDAP_Domain_Search_User = Settings.findOne({ _id: 'LDAP_Domain_Search_User' }); + const LDAP_Domain_Search_Password = Settings.findOne({ _id: 'LDAP_Domain_Search_Password' }); + const LDAP_Domain_Search_Filter = Settings.findOne({ _id: 'LDAP_Domain_Search_Filter' }); - const LDAP_Domain_Search_Object_Class = RocketChat.models.Settings.findOne({ _id: 'LDAP_Domain_Search_Object_Class' }); - const LDAP_Domain_Search_Object_Category = RocketChat.models.Settings.findOne({ _id: 'LDAP_Domain_Search_Object_Category' }); + const LDAP_Domain_Search_Object_Class = Settings.findOne({ _id: 'LDAP_Domain_Search_Object_Class' }); + const LDAP_Domain_Search_Object_Category = Settings.findOne({ _id: 'LDAP_Domain_Search_Object_Category' }); if (LDAP_Use_Custom_Domain_Search) { if (LDAP_Use_Custom_Domain_Search.value === true) { @@ -79,58 +82,58 @@ RocketChat.Migrations.add({ } if (LDAP_Domain_Search_Filter && LDAP_Domain_Search_Filter.value) { - RocketChat.models.Settings.update( + Settings.update( { _id: 'LDAP_User_Search_Filter' }, { $set: { value: LDAP_Domain_Search_Filter.value } } ); } - RocketChat.models.Settings.remove({ _id: 'LDAP_Domain_Search_Filter' }); + Settings.remove({ _id: 'LDAP_Domain_Search_Filter' }); if (LDAP_Domain_Search_User && LDAP_Domain_Search_User.value) { - RocketChat.models.Settings.update( + Settings.update( { _id: 'LDAP_Authentication_UserDN' }, { $set: { value: LDAP_Domain_Search_User.value } } ); } - RocketChat.models.Settings.remove({ _id: 'LDAP_Domain_Search_User' }); + Settings.remove({ _id: 'LDAP_Domain_Search_User' }); if (LDAP_Domain_Search_Password && LDAP_Domain_Search_Password.value) { - RocketChat.models.Settings.update( + Settings.update( { _id: 'LDAP_Authentication_Password' }, { $set: { value: LDAP_Domain_Search_Password.value } } ); } - RocketChat.models.Settings.remove({ _id: 'LDAP_Domain_Search_Password' }); + Settings.remove({ _id: 'LDAP_Domain_Search_Password' }); if (LDAP_Domain_Search_User && LDAP_Domain_Search_User.value && LDAP_Domain_Search_Password && LDAP_Domain_Search_Password.value) { - RocketChat.models.Settings.update( + Settings.update( { _id: 'LDAP_Authentication' }, { $set: { value: true } } ); } - RocketChat.models.Settings.remove({ _id: 'LDAP_Use_Custom_Domain_Search' }); - RocketChat.models.Settings.remove({ _id: 'LDAP_Custom_Domain_Search' }); - RocketChat.models.Settings.remove({ _id: 'LDAP_Domain_Search_Object_Class' }); - RocketChat.models.Settings.remove({ _id: 'LDAP_Domain_Search_Object_Category' }); - RocketChat.models.Settings.remove({ _id: 'LDAP_Sync_Users' }); // Button + Settings.remove({ _id: 'LDAP_Use_Custom_Domain_Search' }); + Settings.remove({ _id: 'LDAP_Custom_Domain_Search' }); + Settings.remove({ _id: 'LDAP_Domain_Search_Object_Class' }); + Settings.remove({ _id: 'LDAP_Domain_Search_Object_Category' }); + Settings.remove({ _id: 'LDAP_Sync_Users' }); // Button - const LDAP_Sync_User_Data = RocketChat.models.Settings.findOne({ _id: 'LDAP_Sync_User_Data' }); + const LDAP_Sync_User_Data = Settings.findOne({ _id: 'LDAP_Sync_User_Data' }); if (LDAP_Sync_User_Data && LDAP_Sync_User_Data.value) { - RocketChat.models.Settings.update( + Settings.update( { _id: 'LDAP_Background_Sync' }, { $set: { value: true } } ); } - const LDAP_Import_Users = RocketChat.models.Settings.findOne({ _id: 'LDAP_Import_Users' }); + const LDAP_Import_Users = Settings.findOne({ _id: 'LDAP_Import_Users' }); if (LDAP_Import_Users && LDAP_Import_Users.value === false) { - RocketChat.models.Settings.update( + Settings.update( { _id: 'LDAP_Background_Sync_Import_New_Users' }, { $set: { value: false } } ); } - RocketChat.models.Settings.remove({ _id: 'LDAP_Import_Users' }); + Settings.remove({ _id: 'LDAP_Import_Users' }); }, }); diff --git a/server/startup/migrations/v103.js b/server/startup/migrations/v103.js index 479ee4016cf55..6854d171da39a 100644 --- a/server/startup/migrations/v103.js +++ b/server/startup/migrations/v103.js @@ -1,3 +1,6 @@ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + const majorColors = { 'content-background-color': '#FFFFFF', 'primary-background-color': '#04436A', @@ -62,24 +65,24 @@ function lightenDarkenColor(col, amt) { return (usePound ? '#' : '') + (g | (b << 8) | (r << 16)).toString(16); } -RocketChat.Migrations.add({ +Migrations.add({ version: 103, up() { Object.keys(majorColors).forEach(function(_id) { - const color = RocketChat.models.Settings.findOne({ _id: `theme-color-${ _id }` }); + const color = Settings.findOne({ _id: `theme-color-${ _id }` }); const key = newvariables[_id]; if (color && color.value !== majorColors[_id] && key) { if (/^@.+/.test(color.value)) { color.value = newvariables[color.value.replace('@', '')]; } const id = `theme-color-${ key }`; - RocketChat.models.Settings.update({ _id: id }, { $set: { value : color.value, editor: /^#.+/.test(color.value) ? 'color' : 'expression' } }); + Settings.update({ _id: id }, { $set: { value : color.value, editor: /^#.+/.test(color.value) ? 'color' : 'expression' } }); if (key === 'rc-color-primary') { - RocketChat.models.Settings.update({ _id: 'theme-color-rc-color-primary-darkest' }, { $set: { editor: 'color', value: lightenDarkenColor(color.value, -16) } }); - RocketChat.models.Settings.update({ _id: 'theme-color-rc-color-primary-dark' }, { $set: { editor: 'color', value: lightenDarkenColor(color.value, 18) } }); - RocketChat.models.Settings.update({ _id: 'theme-color-rc-color-primary-light' }, { $set: { editor: 'color', value: lightenDarkenColor(color.value, 110) } }); - RocketChat.models.Settings.update({ _id: 'theme-color-rc-color-primary-light-medium' }, { $set: { editor: 'color', value: lightenDarkenColor(color.value, 156) } }); - RocketChat.models.Settings.update({ _id: 'theme-color-rc-color-primary-lightest' }, { $set: { editor: 'color', value: lightenDarkenColor(color.value, 200) } }); + Settings.update({ _id: 'theme-color-rc-color-primary-darkest' }, { $set: { editor: 'color', value: lightenDarkenColor(color.value, -16) } }); + Settings.update({ _id: 'theme-color-rc-color-primary-dark' }, { $set: { editor: 'color', value: lightenDarkenColor(color.value, 18) } }); + Settings.update({ _id: 'theme-color-rc-color-primary-light' }, { $set: { editor: 'color', value: lightenDarkenColor(color.value, 110) } }); + Settings.update({ _id: 'theme-color-rc-color-primary-light-medium' }, { $set: { editor: 'color', value: lightenDarkenColor(color.value, 156) } }); + Settings.update({ _id: 'theme-color-rc-color-primary-lightest' }, { $set: { editor: 'color', value: lightenDarkenColor(color.value, 200) } }); } } }); diff --git a/server/startup/migrations/v104.js b/server/startup/migrations/v104.js index 2d1690b913d4a..e78faea66255b 100644 --- a/server/startup/migrations/v104.js +++ b/server/startup/migrations/v104.js @@ -1,19 +1,22 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 104, up() { - if ((RocketChat.models.Settings.findOne({ _id: 'theme-color-rc-color-primary' }) || {}).value === '#04436A' && - (RocketChat.models.Settings.findOne({ _id: 'theme-color-rc-color-primary-darkest' }) || {}).value === '#335a' && - (RocketChat.models.Settings.findOne({ _id: 'theme-color-rc-color-primary-dark' }) || {}).value === '#16557c' && - (RocketChat.models.Settings.findOne({ _id: 'theme-color-rc-color-primary-light' }) || {}).value === '#72b1d8' && - (RocketChat.models.Settings.findOne({ _id: 'theme-color-rc-color-primary-light-medium' }) || {}).value === '#a0dfff' && - (RocketChat.models.Settings.findOne({ _id: 'theme-color-rc-color-primary-lightest' }) || {}).value === '#ccffff' + if ((Settings.findOne({ _id: 'theme-color-rc-color-primary' }) || {}).value === '#04436A' && + (Settings.findOne({ _id: 'theme-color-rc-color-primary-darkest' }) || {}).value === '#335a' && + (Settings.findOne({ _id: 'theme-color-rc-color-primary-dark' }) || {}).value === '#16557c' && + (Settings.findOne({ _id: 'theme-color-rc-color-primary-light' }) || {}).value === '#72b1d8' && + (Settings.findOne({ _id: 'theme-color-rc-color-primary-light-medium' }) || {}).value === '#a0dfff' && + (Settings.findOne({ _id: 'theme-color-rc-color-primary-lightest' }) || {}).value === '#ccffff' ) { - RocketChat.models.Settings.update({ _id: 'theme-color-rc-color-primary' }, { $set: { editor: 'expression', value: 'color-dark' } }); - RocketChat.models.Settings.update({ _id: 'theme-color-rc-color-primary-darkest' }, { $set: { editor: 'expression', value: 'color-darkest' } }); - RocketChat.models.Settings.update({ _id: 'theme-color-rc-color-primary-dark' }, { $set: { editor: 'expression', value: 'color-dark-medium' } }); - RocketChat.models.Settings.update({ _id: 'theme-color-rc-color-primary-light' }, { $set: { editor: 'expression', value: 'color-gray' } }); - RocketChat.models.Settings.update({ _id: 'theme-color-rc-color-primary-light-medium' }, { $set: { editor: 'expression', value: 'color-gray-medium' } }); - RocketChat.models.Settings.update({ _id: 'theme-color-rc-color-primary-lightest' }, { $set: { editor: 'expression', value: 'color-gray-lightest' } }); + Settings.update({ _id: 'theme-color-rc-color-primary' }, { $set: { editor: 'expression', value: 'color-dark' } }); + Settings.update({ _id: 'theme-color-rc-color-primary-darkest' }, { $set: { editor: 'expression', value: 'color-darkest' } }); + Settings.update({ _id: 'theme-color-rc-color-primary-dark' }, { $set: { editor: 'expression', value: 'color-dark-medium' } }); + Settings.update({ _id: 'theme-color-rc-color-primary-light' }, { $set: { editor: 'expression', value: 'color-gray' } }); + Settings.update({ _id: 'theme-color-rc-color-primary-light-medium' }, { $set: { editor: 'expression', value: 'color-gray-medium' } }); + Settings.update({ _id: 'theme-color-rc-color-primary-lightest' }, { $set: { editor: 'expression', value: 'color-gray-lightest' } }); } }, }); diff --git a/server/startup/migrations/v105.js b/server/startup/migrations/v105.js index 5c72bf168344c..52377718614f7 100644 --- a/server/startup/migrations/v105.js +++ b/server/startup/migrations/v105.js @@ -1,31 +1,32 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users, Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 105, up() { - if (RocketChat && RocketChat.models) { - if (RocketChat.models.Users) { - RocketChat.models.Users.find({ 'settings.preferences.unreadRoomsMode': { $exists: 1 } }).forEach(function(user) { - const newPreference = user.settings.preferences.unreadRoomsMode ? 'unread' : 'category'; - RocketChat.models.Users.update({ _id: user._id }, { $unset: { 'settings.preferences.unreadRoomsMode': 1 }, $set: { 'settings.preferences.roomsListExhibitionMode': newPreference } }); - }); - } - if (RocketChat.models.Settings) { - const settingsMap = { - Desktop_Notifications_Default_Alert: 'Accounts_Default_User_Preferences_desktopNotifications', - Mobile_Notifications_Default_Alert: 'Accounts_Default_User_Preferences_mobileNotifications', - Audio_Notifications_Default_Alert: 'Accounts_Default_User_Preferences_audioNotifications', - Desktop_Notifications_Duration: 'Accounts_Default_User_Preferences_desktopNotificationDuration', - Audio_Notifications_Value: undefined, - }; - RocketChat.models.Settings.find({ _id: { $in: Object.keys(settingsMap) } }).forEach((oldSetting) => { - const newSettingKey = settingsMap[oldSetting._id]; - const newSetting = newSettingKey && RocketChat.models.Settings.findOne({ _id: newSettingKey }); + if (Users) { + Users.find({ 'settings.preferences.unreadRoomsMode': { $exists: 1 } }).forEach(function(user) { + const newPreference = user.settings.preferences.unreadRoomsMode ? 'unread' : 'category'; + Users.update({ _id: user._id }, { $unset: { 'settings.preferences.unreadRoomsMode': 1 }, $set: { 'settings.preferences.roomsListExhibitionMode': newPreference } }); + }); + } + if (Settings) { + const settingsMap = { + Desktop_Notifications_Default_Alert: 'Accounts_Default_User_Preferences_desktopNotifications', + Mobile_Notifications_Default_Alert: 'Accounts_Default_User_Preferences_mobileNotifications', + Audio_Notifications_Default_Alert: 'Accounts_Default_User_Preferences_audioNotifications', + Desktop_Notifications_Duration: 'Accounts_Default_User_Preferences_desktopNotificationDuration', + Audio_Notifications_Value: undefined, + }; + Settings.find({ _id: { $in: Object.keys(settingsMap) } }).forEach((oldSetting) => { + const newSettingKey = settingsMap[oldSetting._id]; + const newSetting = newSettingKey && Settings.findOne({ _id: newSettingKey }); - if (newSetting && newSetting.value !== oldSetting.value) { - RocketChat.models.Settings.update({ _id: newSettingKey }, { $set: { value: oldSetting.value } }); - } - RocketChat.models.Settings.remove({ _id: oldSetting._id }); - }); - } + if (newSetting && newSetting.value !== oldSetting.value) { + Settings.update({ _id: newSettingKey }, { $set: { value: oldSetting.value } }); + } + Settings.remove({ _id: oldSetting._id }); + }); } }, }); diff --git a/server/startup/migrations/v106.js b/server/startup/migrations/v106.js index 6186e3beb339f..54914a03b5903 100644 --- a/server/startup/migrations/v106.js +++ b/server/startup/migrations/v106.js @@ -1,7 +1,8 @@ import { Meteor } from 'meteor/meteor'; import { LivechatVisitors } from 'meteor/rocketchat:models'; +import { Migrations } from 'meteor/rocketchat:migrations'; -RocketChat.Migrations.add({ +Migrations.add({ version: 106, up() { const visitors = Meteor.users.find({ type: 'visitor' }); diff --git a/server/startup/migrations/v107.js b/server/startup/migrations/v107.js index b66e8d380a183..5eb2a833bddcf 100644 --- a/server/startup/migrations/v107.js +++ b/server/startup/migrations/v107.js @@ -1,11 +1,12 @@ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users } from 'meteor/rocketchat:models'; - -RocketChat.Migrations.add({ +Migrations.add({ version: 107, up() { - RocketChat.models.Users.update({ + Users.update({ 'preferences.roomsListExhibitionMode': 'activity', }, { $unset: { @@ -17,7 +18,7 @@ RocketChat.Migrations.add({ }, }); - RocketChat.models.Users.update({ + Users.update({ 'preferences.roomsListExhibitionMode': 'unread', }, { $unset: { @@ -30,7 +31,7 @@ RocketChat.Migrations.add({ }, }); - RocketChat.models.Users.update({ + Users.update({ 'preferences.roomsListExhibitionMode': 'category', }, { $unset: { diff --git a/server/startup/migrations/v108.js b/server/startup/migrations/v108.js index d25c064be435b..54f1632c7a729 100644 --- a/server/startup/migrations/v108.js +++ b/server/startup/migrations/v108.js @@ -1,11 +1,14 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Permissions, Roles } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 108, up() { - const roles = RocketChat.models.Roles.find({ + const roles = Roles.find({ _id: { $ne: 'guest' }, scope: 'Users', }).fetch().map((role) => role._id); - RocketChat.models.Permissions.createOrUpdate('leave-c', roles); - RocketChat.models.Permissions.createOrUpdate('leave-d', roles); + Permissions.createOrUpdate('leave-c', roles); + Permissions.createOrUpdate('leave-d', roles); }, }); diff --git a/server/startup/migrations/v109.js b/server/startup/migrations/v109.js index c0baf24a6ae35..979405e3f5f2c 100644 --- a/server/startup/migrations/v109.js +++ b/server/startup/migrations/v109.js @@ -1,16 +1,19 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 109, up() { - const FileUpload_GoogleStorage_Proxy = (RocketChat.models.Settings.findOne({ _id: 'FileUpload_GoogleStorage_Proxy' }) || {}).value === true; - const FileUpload_S3_Proxy = (RocketChat.models.Settings.findOne({ _id: 'FileUpload_S3_Proxy' }) || {}).value === true; + const FileUpload_GoogleStorage_Proxy = (Settings.findOne({ _id: 'FileUpload_GoogleStorage_Proxy' }) || {}).value === true; + const FileUpload_S3_Proxy = (Settings.findOne({ _id: 'FileUpload_S3_Proxy' }) || {}).value === true; - RocketChat.models.Settings.update({ _id: 'FileUpload_GoogleStorage_Proxy_Avatars' }, { $set: { value: FileUpload_GoogleStorage_Proxy } }); - RocketChat.models.Settings.update({ _id: 'FileUpload_GoogleStorage_Proxy_Uploads' }, { $set: { value: FileUpload_GoogleStorage_Proxy } }); + Settings.update({ _id: 'FileUpload_GoogleStorage_Proxy_Avatars' }, { $set: { value: FileUpload_GoogleStorage_Proxy } }); + Settings.update({ _id: 'FileUpload_GoogleStorage_Proxy_Uploads' }, { $set: { value: FileUpload_GoogleStorage_Proxy } }); - RocketChat.models.Settings.update({ _id: 'FileUpload_S3_Proxy_Avatars' }, { $set: { value: FileUpload_S3_Proxy } }); - RocketChat.models.Settings.update({ _id: 'FileUpload_S3_Proxy_Uploads' }, { $set: { value: FileUpload_S3_Proxy } }); + Settings.update({ _id: 'FileUpload_S3_Proxy_Avatars' }, { $set: { value: FileUpload_S3_Proxy } }); + Settings.update({ _id: 'FileUpload_S3_Proxy_Uploads' }, { $set: { value: FileUpload_S3_Proxy } }); - RocketChat.models.Settings.remove({ _id: 'FileUpload_GoogleStorage_Proxy' }); - RocketChat.models.Settings.remove({ _id: 'FileUpload_S3_Proxy' }); + Settings.remove({ _id: 'FileUpload_GoogleStorage_Proxy' }); + Settings.remove({ _id: 'FileUpload_S3_Proxy' }); }, }); diff --git a/server/startup/migrations/v110.js b/server/startup/migrations/v110.js index d4637e9965055..4c6652120d358 100644 --- a/server/startup/migrations/v110.js +++ b/server/startup/migrations/v110.js @@ -1,53 +1,50 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings, Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 110, up() { - if (RocketChat && RocketChat.models) { - - if (RocketChat.models.Settings) { - const setting = RocketChat.models.Settings.findOne({ _id: 'Accounts_Default_User_Preferences_viewMode' }); - if (setting && setting.value) { - RocketChat.models.Settings.update( - { _id: 'Accounts_Default_User_Preferences_messageViewMode' }, - { $set: { value: setting.value } } - ); - - RocketChat.models.Settings.remove( - { _id: 'Accounts_Default_User_Preferences_viewMode' } - ); - } - } + if (Settings) { + const setting = Settings.findOne({ _id: 'Accounts_Default_User_Preferences_viewMode' }); + if (setting && setting.value) { + Settings.update( + { _id: 'Accounts_Default_User_Preferences_messageViewMode' }, + { $set: { value: setting.value } } + ); - if (RocketChat.models.Users) { - RocketChat.models.Users.update( - { 'settings.preferences.viewMode': { $exists: 1 } }, - { $rename: { 'settings.preferences.viewMode': 'user.settings.preferences.messageViewMode' } }, + Settings.remove( + { _id: 'Accounts_Default_User_Preferences_viewMode' } ); } } + + if (Users) { + Users.update( + { 'settings.preferences.viewMode': { $exists: 1 } }, + { $rename: { 'settings.preferences.viewMode': 'user.settings.preferences.messageViewMode' } }, + ); + } }, down() { - if (RocketChat && RocketChat.models) { - - if (RocketChat.models.Settings) { - const setting = RocketChat.models.Settings.findOne({ _id: 'Accounts_Default_User_Preferences_messageViewMode' }); - if (setting && setting.value) { - RocketChat.models.Settings.update( - { _id: 'Accounts_Default_User_Preferences_viewMode' }, - { $set: { value: setting.value } } - ); - - RocketChat.models.Settings.remove( - { _id: 'Accounts_Default_User_Preferences_messageViewMode' } - ); - } - } + if (Settings) { + const setting = Settings.findOne({ _id: 'Accounts_Default_User_Preferences_messageViewMode' }); + if (setting && setting.value) { + Settings.update( + { _id: 'Accounts_Default_User_Preferences_viewMode' }, + { $set: { value: setting.value } } + ); - if (RocketChat.models.Users) { - RocketChat.models.Users.update( - { 'settings.preferences.messageViewMode': { $exists: 1 } }, - { $rename: { 'settings.preferences.messageViewMode': 'user.settings.preferences.viewMode' } }, + Settings.remove( + { _id: 'Accounts_Default_User_Preferences_messageViewMode' } ); } } + + if (Users) { + Users.update( + { 'settings.preferences.messageViewMode': { $exists: 1 } }, + { $rename: { 'settings.preferences.messageViewMode': 'user.settings.preferences.viewMode' } }, + ); + } }, }); diff --git a/server/startup/migrations/v111.js b/server/startup/migrations/v111.js index d6ddbf2dca5d6..79783455ceb65 100644 --- a/server/startup/migrations/v111.js +++ b/server/startup/migrations/v111.js @@ -1,10 +1,13 @@ // Migration to give delete channel, delete group permissions to owner -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Permissions } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 111, up() { - if (RocketChat.models && RocketChat.models.Permissions) { - RocketChat.models.Permissions.update({ _id: 'delete-c' }, { $addToSet: { roles: 'owner' } }); - RocketChat.models.Permissions.update({ _id: 'delete-p' }, { $addToSet: { roles: 'owner' } }); + if (Permissions) { + Permissions.update({ _id: 'delete-c' }, { $addToSet: { roles: 'owner' } }); + Permissions.update({ _id: 'delete-p' }, { $addToSet: { roles: 'owner' } }); } }, }); diff --git a/server/startup/migrations/v112.js b/server/startup/migrations/v112.js index 72d4a4cdf21cc..ff8d2914fb2b2 100644 --- a/server/startup/migrations/v112.js +++ b/server/startup/migrations/v112.js @@ -1,25 +1,26 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings, Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 112, up() { - if (RocketChat && RocketChat.models) { - if (RocketChat.models.Settings) { - const setting = RocketChat.models.Settings.findOne({ _id: 'Accounts_Default_User_Preferences_idleTimeoutLimit' }); - if (setting && setting.value) { - RocketChat.models.Settings.update( - { _id: 'Accounts_Default_User_Preferences_idleTimeoutLimit' }, - { $set: { value: setting.value / 1000 } } - ); - } + if (Settings) { + const setting = Settings.findOne({ _id: 'Accounts_Default_User_Preferences_idleTimeoutLimit' }); + if (setting && setting.value) { + Settings.update( + { _id: 'Accounts_Default_User_Preferences_idleTimeoutLimit' }, + { $set: { value: setting.value / 1000 } } + ); } + } - if (RocketChat.models.Users) { - RocketChat.models.Users.find({ 'settings.preferences.idleTimeLimit': { $exists: 1 } }).forEach(function(user) { - RocketChat.models.Users.update( - { _id: user._id }, - { $set: { 'settings.preferences.idleTimeLimit': user.settings.preferences.idleTimeLimit / 1000 } } - ); - }); - } + if (Users) { + Users.find({ 'settings.preferences.idleTimeLimit': { $exists: 1 } }).forEach(function(user) { + Users.update( + { _id: user._id }, + { $set: { 'settings.preferences.idleTimeLimit': user.settings.preferences.idleTimeLimit / 1000 } } + ); + }); } }, }); diff --git a/server/startup/migrations/v113.js b/server/startup/migrations/v113.js index 2f1d96b5a6970..e7ac0986bc7f9 100644 --- a/server/startup/migrations/v113.js +++ b/server/startup/migrations/v113.js @@ -1,17 +1,20 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Uploads, Messages } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 113, up() { - if (RocketChat && RocketChat.models && RocketChat.models.Uploads && RocketChat.models.Messages) { + if (Uploads && Messages) { const fileQuery = { userId: null, }; - const filesToUpdate = RocketChat.models.Uploads.find(fileQuery); + const filesToUpdate = Uploads.find(fileQuery); filesToUpdate.forEach((file) => { const messageQuery = { 'file._id' : file._id, }; - const message = RocketChat.models.Messages.findOne(messageQuery); + const message = Messages.findOne(messageQuery); if (message) { const filter = { _id: file._id, @@ -23,7 +26,7 @@ RocketChat.Migrations.add({ }, }; - RocketChat.models.Uploads.model.direct.update(filter, update); + Uploads.model.direct.update(filter, update); } }); } diff --git a/server/startup/migrations/v114.js b/server/startup/migrations/v114.js index bd24b336a28cb..a7ec643c8dd71 100644 --- a/server/startup/migrations/v114.js +++ b/server/startup/migrations/v114.js @@ -1,17 +1,18 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 114, up() { - if (RocketChat && RocketChat.models) { - if (RocketChat.models.Settings) { - const setting = RocketChat.models.Settings.findOne({ _id: 'Message_GlobalSearch' }); - if (setting && setting.value) { - RocketChat.models.Settings.upsert( - { _id: 'Search.defaultProvider.GlobalSearchEnabled' }, - { $set: { value: setting.value } } - ); + if (Settings) { + const setting = Settings.findOne({ _id: 'Message_GlobalSearch' }); + if (setting && setting.value) { + Settings.upsert( + { _id: 'Search.defaultProvider.GlobalSearchEnabled' }, + { $set: { value: setting.value } } + ); - RocketChat.models.Settings.removeById('Message_GlobalSearch'); - } + Settings.removeById('Message_GlobalSearch'); } } }, diff --git a/server/startup/migrations/v115.js b/server/startup/migrations/v115.js index d81f20437ef6d..45b624f5f378b 100644 --- a/server/startup/migrations/v115.js +++ b/server/startup/migrations/v115.js @@ -1,7 +1,10 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Rooms } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 115, up() { - RocketChat.models.Rooms.update({ + Rooms.update({ 'announcement.message': { $exists: true }, }, { $unset: { announcement: 1 }, diff --git a/server/startup/migrations/v116.js b/server/startup/migrations/v116.js index 6ed04dcc3740f..3f41d6c763931 100644 --- a/server/startup/migrations/v116.js +++ b/server/startup/migrations/v116.js @@ -1,12 +1,15 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Subscriptions, Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 116, up() { - RocketChat.models.Subscriptions.tryDropIndex({ + Subscriptions.tryDropIndex({ unread: 1, }); // set pref origin to all existing preferences - RocketChat.models.Subscriptions.update({ + Subscriptions.update({ desktopNotifications: { $exists: true }, }, { $set: { @@ -15,7 +18,7 @@ RocketChat.Migrations.add({ }, { multi: true, }); - RocketChat.models.Subscriptions.update({ + Subscriptions.update({ mobilePushNotifications: { $exists: true }, }, { $set: { @@ -24,7 +27,7 @@ RocketChat.Migrations.add({ }, { multi: true, }); - RocketChat.models.Subscriptions.update({ + Subscriptions.update({ emailNotifications: { $exists: true }, }, { $set: { @@ -35,7 +38,7 @@ RocketChat.Migrations.add({ }); // set user preferences on subscriptions - RocketChat.models.Users.find({ + Users.find({ $or: [ { 'settings.preferences.desktopNotifications': { $exists: true } }, { 'settings.preferences.mobileNotifications': { $exists: true } }, @@ -43,7 +46,7 @@ RocketChat.Migrations.add({ ], }).forEach((user) => { if (user.settings.preferences.desktopNotifications && user.settings.preferences.desktopNotifications !== 'default') { - RocketChat.models.Subscriptions.update({ + Subscriptions.update({ 'u._id': user._id, desktopPrefOrigin: { $exists: false }, }, { @@ -57,7 +60,7 @@ RocketChat.Migrations.add({ } if (user.settings.preferences.mobileNotifications && user.settings.preferences.mobileNotifications !== 'default') { - RocketChat.models.Subscriptions.update({ + Subscriptions.update({ 'u._id': user._id, mobilePrefOrigin: { $exists: false }, }, { @@ -71,7 +74,7 @@ RocketChat.Migrations.add({ } if (user.settings.preferences.emailNotificationMode && user.settings.preferences.emailNotificationMode !== 'default') { - RocketChat.models.Subscriptions.update({ + Subscriptions.update({ 'u._id': user._id, emailPrefOrigin: { $exists: false }, }, { diff --git a/server/startup/migrations/v117.js b/server/startup/migrations/v117.js index cd88aae50d67c..4715819e321fa 100644 --- a/server/startup/migrations/v117.js +++ b/server/startup/migrations/v117.js @@ -1,11 +1,12 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; +import { getUsersInRole } from 'meteor/rocketchat:authorization'; + +Migrations.add({ version: 117, up() { - if (RocketChat.authz && - RocketChat.models && - RocketChat.models.Settings && - RocketChat.authz.getUsersInRole('admin').count()) { - RocketChat.models.Settings.upsert( + if (Settings && getUsersInRole('admin').count()) { + Settings.upsert( { _id: 'Show_Setup_Wizard', }, { diff --git a/server/startup/migrations/v118.js b/server/startup/migrations/v118.js index 3c857a5f02b0b..93cb92507fa79 100644 --- a/server/startup/migrations/v118.js +++ b/server/startup/migrations/v118.js @@ -1,7 +1,10 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Subscriptions, Settings, Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 118, up() { - RocketChat.models.Subscriptions.update({ + Subscriptions.update({ emailNotifications: 'all', emailPrefOrigin: 'user', }, { @@ -12,7 +15,7 @@ RocketChat.Migrations.add({ multi:true, }); - RocketChat.models.Users.update({ + Users.update({ 'settings.preferences.emailNotificationMode': 'disabled', }, { $set: { @@ -22,7 +25,7 @@ RocketChat.Migrations.add({ multi:true, }); - RocketChat.models.Users.update({ + Users.update({ 'settings.preferences.emailNotificationMode': 'all', }, { $set: { @@ -32,7 +35,7 @@ RocketChat.Migrations.add({ multi:true, }); - RocketChat.models.Settings.update({ + Settings.update({ _id: 'Accounts_Default_User_Preferences_emailNotificationMode', value: 'disabled', }, { @@ -41,7 +44,7 @@ RocketChat.Migrations.add({ }, }); - RocketChat.models.Settings.update({ + Settings.update({ _id: 'Accounts_Default_User_Preferences_emailNotificationMode', value: 'all', }, { @@ -51,14 +54,14 @@ RocketChat.Migrations.add({ }); // set user highlights on subscriptions - RocketChat.models.Users.find({ + Users.find({ 'settings.preferences.highlights.0': { $exists: true }, }, { fields: { 'settings.preferences.highlights': 1, }, }).forEach((user) => { - RocketChat.models.Subscriptions.update({ + Subscriptions.update({ 'u._id': user._id, }, { $set: { diff --git a/server/startup/migrations/v119.js b/server/startup/migrations/v119.js index 63666c1453fae..e18aa5adfd604 100644 --- a/server/startup/migrations/v119.js +++ b/server/startup/migrations/v119.js @@ -1,15 +1,18 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Settings } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 119, up() { - if (RocketChat.models && RocketChat.models.Settings) { - RocketChat.models.Settings.update({ + if (Settings) { + Settings.update({ _id: 'Show_Setup_Wizard', value: true, }, { $set: { value: 'pending' }, }); - RocketChat.models.Settings.update({ + Settings.update({ _id: 'Show_Setup_Wizard', value: false, }, { diff --git a/server/startup/migrations/v120.js b/server/startup/migrations/v120.js index 473a9c1807957..2897dd0cff23b 100644 --- a/server/startup/migrations/v120.js +++ b/server/startup/migrations/v120.js @@ -1,7 +1,10 @@ -RocketChat.Migrations.add({ +import { Migrations } from 'meteor/rocketchat:migrations'; +import { Users } from 'meteor/rocketchat:models'; + +Migrations.add({ version: 120, up() { - RocketChat.models.Users.update({ + Users.update({ 'settings.preferences.roomsListExhibitionMode': 'activity', }, { $unset: { @@ -13,7 +16,7 @@ RocketChat.Migrations.add({ }, }); - RocketChat.models.Users.update({ + Users.update({ 'settings.preferences.roomsListExhibitionMode': 'unread', }, { $unset: { @@ -26,7 +29,7 @@ RocketChat.Migrations.add({ }, }); - RocketChat.models.Users.update({ + Users.update({ 'settings.preferences.roomsListExhibitionMode': 'category', }, { $unset: {