From f42304c967a62e5a4c569261846990d1769268e3 Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Sat, 21 Mar 2020 21:03:52 +0100 Subject: Clean up all foreign-key constraints This patch cleans up the remaining possible foreign-key constraint. This case seem to appear, when notes are deleted, but due to missing database contraints not their authroships. This function should clean that up as well and complete the preparation for the new db contraints. Signed-off-by: Sheogorath --- bin/cleanup | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bin/cleanup b/bin/cleanup index 6ccbb07d..b77fdb4e 100755 --- a/bin/cleanup +++ b/bin/cleanup @@ -55,6 +55,26 @@ async function cleanup() { } }) + await models.Author.findAll({ + include: [{ + model: models.Note, + as: 'note', + attributes: ['id'] + }], + attributes: ['id', 'noteId'] + }).then(async function(authors) { + for(let i =0, authorCount = authors.length; i< authorCount; i++) { + const item = authors[i] + if(item.noteId != null && !item.note) { + await models.Author.destroy({ + where: { + id: item.id + }}) + logger.info(`Deleted authorship ${item.id} from note ${item.noteId}`) + } + } + }) + await models.Revision.findAll({ include: [{ model: models.Note, -- cgit v1.2.3