Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RocketChat/Rocket.Chat#12 Prefix settings and oembed_cache collections with rocketchat_ #317

Merged
merged 1 commit into from
Jul 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/rocketchat-lib/settings/lib/settings.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@Settings = new Meteor.Collection 'settings'
@Settings = new Meteor.Collection 'rocketchat_settings'

Settings.find().observe
added: (record) ->
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-oembed/server/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 18 additions & 2 deletions server/startup/migrations/v9.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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.
Expand Down