From 098d80094ab23cfd2f3c813bdbc3cff7a021cfe6 Mon Sep 17 00:00:00 2001 From: George Secrieru Date: Fri, 2 Oct 2015 14:50:24 -0300 Subject: [PATCH] Added room Id field for better relationship between objects. --- client/lib/fileUpload.coffee | 1 + server/startup/migrations/v20.coffee | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 server/startup/migrations/v20.coffee diff --git a/client/lib/fileUpload.coffee b/client/lib/fileUpload.coffee index 11476a2b3909..533f20a70b32 100644 --- a/client/lib/fileUpload.coffee +++ b/client/lib/fileUpload.coffee @@ -62,6 +62,7 @@ readAsArrayBuffer = (file, callback) -> name: file.name or file.file.name size: file.file.size type: file.file.type + rid: roomId upload = new UploadFS.Uploader store: Meteor.fileStore diff --git a/server/startup/migrations/v20.coffee b/server/startup/migrations/v20.coffee new file mode 100644 index 000000000000..19c569551ec9 --- /dev/null +++ b/server/startup/migrations/v20.coffee @@ -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.'