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
No known key found for this signature in database
GPG key ID: C9B1C80737B9CE18

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({ await models.Revision.findAll({
include: [{ include: [{
model: models.Note, model: models.Note,