-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #965 from RocketChat/uploads-with-room-id
Added room Id field for better relationship between objects.
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Meteor.startup -> | ||
Migrations.add | ||
version: 20 | ||
up: -> | ||
### | ||
# Migrate existing `rocketchat_uploads` documents to include the room Id | ||
# where the file was uploaded to. The room Id is retrieved from the message | ||
# document created after the file upload. | ||
### | ||
|
||
# list of channel messages which were created after uploading a file | ||
msgQuery = | ||
rid: { $exists: true } | ||
'file._id': { $exists: true } | ||
msgOptions = | ||
fields: | ||
_id: 1 | ||
rid: 1 | ||
'file._id': 1 | ||
cursorFileMessages = RocketChat.models.Messages.find(msgQuery, msgOptions); | ||
return unless cursorFileMessages.count() | ||
|
||
_.each( cursorFileMessages.fetch(), (msg) -> | ||
fileCollection.update({ _id: msg?.file?._id }, { $set: { rid: msg.rid } }, { $multi: true }) | ||
) | ||
|
||
console.log 'Updated rocketchat_uploads documents to include the room Id in which they were sent.' |