From 7033315cd36530330af6f785716cce9342ef4a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Manelli?= Date: Sun, 24 Feb 2019 12:55:34 +0100 Subject: Add migrations --- server/migrations.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/server/migrations.js b/server/migrations.js index 8dcd892a..cb64b7e8 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -422,3 +422,98 @@ Migrations.add('add-defaultAuthenticationMethod', () => { }, }, noValidateMulti); }); + +Migrations.add('add-templates', () => { + Boards.update({ + type: { + $exists: false, + }, + }, { + $set: { + type: 'board', + }, + }, noValidateMulti); + Swimlanes.update({ + type: { + $exists: false, + }, + }, { + $set: { + type: 'swimlane', + }, + }, noValidateMulti); + Lists.update({ + type: { + $exists: false, + }, + swimlaneId: { + $exists: false, + }, + }, { + $set: { + type: 'list', + swimlaneId: '', + }, + }, noValidateMulti); + Users.find({ + 'profile.templatesBoardId': { + $exists: false, + }, + }).forEach((user) => { + // Create board and swimlanes + Boards.insert({ + title: TAPi18n.__('templates'), + permission: 'private', + type: 'template-container', + members: [ + { + userId: user._id, + isAdmin: true, + isActive: true, + isNoComments: false, + isCommentOnly: false, + }, + ], + }, (err, boardId) => { + + // Insert the reference to our templates board + Users.update(user._id, {$set: {'profile.templatesBoardId': boardId}}); + + // Insert the card templates swimlane + Swimlanes.insert({ + title: TAPi18n.__('card-templates-swimlane'), + boardId, + sort: 1, + type: 'template-container', + }, (err, swimlaneId) => { + + // Insert the reference to out card templates swimlane + Users.update(user._id, {$set: {'profile.cardTemplatesSwimlaneId': swimlaneId}}); + }); + + // Insert the list templates swimlane + Swimlanes.insert({ + title: TAPi18n.__('list-templates-swimlane'), + boardId, + sort: 2, + type: 'template-container', + }, (err, swimlaneId) => { + + // Insert the reference to out list templates swimlane + Users.update(user._id, {$set: {'profile.listTemplatesSwimlaneId': swimlaneId}}); + }); + + // Insert the board templates swimlane + Swimlanes.insert({ + title: TAPi18n.__('board-templates-swimlane'), + boardId, + sort: 3, + type: 'template-container', + }, (err, swimlaneId) => { + + // Insert the reference to out board templates swimlane + Users.update(user._id, {$set: {'profile.boardTemplatesSwimlaneId': swimlaneId}}); + }); + }); + }); +}); -- cgit v1.2.3-1-g7c22