Skip to content
Snippets Groups Projects
Commit f0dbc567 authored by Reid Wakida's avatar Reid Wakida
Browse files

Migrate settings and oembed_cache collections to rocketchat_settings and

rocketchat_embed_cache. Handle error where oembed_cache doesn't exist.
parent 165ca373
No related branches found
No related tags found
No related merge requests found
@Settings = new Meteor.Collection 'settings'
@Settings = new Meteor.Collection 'rocketchat_settings'
Settings.find().observe
added: (record) ->
......
......@@ -4,7 +4,7 @@ https = Npm.require('https')
querystring = Npm.require('querystring')
OEmbed =
cache: new Meteor.Collection 'oembed_cache'
cache: new Meteor.Collection 'rocketchat_oembed_cache'
getUrlContent = (urlObj, redirectCount = 5, callback) ->
if _.isString(urlObj)
......
......@@ -4,6 +4,7 @@ Meteor.startup ->
up: ->
# Migrate existing source collection data to target collection
# target collection is defined in collections.coffee using the new collection name
# source collection is dropped after data migration
toMigrate = [
{
source: new Meteor.Collection 'data.ChatRoom'
......@@ -17,18 +18,33 @@ Meteor.startup ->
source: new Meteor.Collection 'data.ChatMessage'
target: ChatMessage
}
{
source: new Meteor.Collection 'settings'
target: Settings
}
{
# this collection may not exit
source: new Meteor.Collection 'oembed_cache'
target: OEmbed.cache
}
]
toMigrate.forEach ( collection ) ->
source = collection.source
target = collection.target
# rawCollection available as of Meteor 1.0.4
console.log 'Migrating data from: ' + source.rawCollection().collectionName + ' to: ' + target.rawCollection().collectionName
source.find().forEach ( doc ) ->
# use upsert to account for GENERAL room created by initialData
target.upsert({_id: doc._id}, doc )
rawSource = source.rawCollection();
Meteor.wrapAsync(rawSource.drop, rawSource )()
rawSource = source.rawCollection()
# drop old collection
Meteor.wrapAsync(rawSource.drop, rawSource )((err,res) ->
if err
console.log 'Error dropping ' + rawSource.collectionName + ' collection due to: ' + err.errmsg
)
# Note: the following would have been much easier, but didn't work. The serverside
# data was not published to the client for some reason.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment