From 6ad007a5f17c75a455a37fc19c3001c863a92e36 Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Sun, 9 Jul 2023 23:20:37 +0200 Subject: [PATCH] fix for migration "attachment-cardCopy-fix-boardId-etc" - every card must have a boardId, listId and swimlaneId, if not, the database data is corrupt, but the migration should also not break wekan from startup --- server/migrations.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/server/migrations.js b/server/migrations.js index cb7165f5b..99b0f8da9 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -1425,13 +1425,15 @@ Migrations.add('attachment-cardCopy-fix-boardId-etc', () => { Attachments.find( {"meta.source": "copy"} ).forEach(_attachment => { const cardId = _attachment.meta.cardId; const card = Cards.findOne(cardId); - console.log("update attachment id: ", _attachment._id); - Attachments.update(_attachment._id, { - $set: { - "meta.boardId": card.boardId, - "meta.listId": card.listId, - "meta.swimlaneId": card.swimlaneId, - } - }); + if (card.boardId && card.listId && card.swimlaneId) { + console.log("update attachment id: ", _attachment._id); + Attachments.update(_attachment._id, { + $set: { + "meta.boardId": card.boardId, + "meta.listId": card.listId, + "meta.swimlaneId": card.swimlaneId, + } + }); + } }); });