diff options
author | Sheogorath | 2020-03-21 21:03:52 +0100 |
---|---|---|
committer | Sheogorath | 2020-03-21 21:05:52 +0100 |
commit | f42304c967a62e5a4c569261846990d1769268e3 (patch) | |
tree | db4cb4ebfe4925472ec3fe538cc1ad4a0fcafa37 /bin | |
parent | 41b13e71b6b1d499238c04b15d65e3bd76442f1d (diff) |
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 <sheogorath@shivering-isles.com>
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cleanup | 20 |
1 files changed, 20 insertions, 0 deletions
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, |