diff --git a/server/startup/migrations/v041.js b/server/startup/migrations/v041.js index da2b432743e5..83085e1e5c44 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 e97cb83bf8c9..275d99f1ca44 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 87867c358f49..209d0f60e2dd 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 490643740956..fb6f0a6f4a0f 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 2be7c4ae3fe9..c43b9e837ef3 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 3d171be15ae0..ea167add41c1 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 2ecbe80c7943..082068c4503b 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 731f38ef0886..cce3861e5826 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 635ba13afb42..6bdb839bfd1b 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 769ce1c1cddd..92bb06aa68fa 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 5f1c4da7719b..3c43c1d2ae4c 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 477ed1908552..e1a30bd5941a 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 78c6b10d606e..39534a3580b3 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 29a911f62b55..a44b9db19642 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 1e8cd34ed718..6e840d767118 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 174498b503af..507f7ddf0f0e 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 0f80972aed78..c2a070becbf7 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 bcee11484db0..ec7924da5a0f 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 9e8a0bdcd458..9340604f2dc8 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 d5d3460a98fc..30c3b1ac77d2 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 5f7cae3b2da1..b39f2e20b14d 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 32699b65b552..83a35ad40b8c 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 c2a3efca6a15..66e56986c70b 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 84445248e82e..84ece66ae7fd 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 975b91c8452e..49ab36f4924e 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 0fed3e168a3b..bd697c825988 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 4b508f1f51fe..ccfa5769dcfd 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 7852347a92a4..d07fd736951b 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 }); }, });