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>
This commit is contained in:
Sheogorath
2020-03-21 21:03:52 +01:00
parent 41b13e71b6
commit f42304c967

View File

@@ -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,