mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 17:26:29 -05:00
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:
parent
41b13e71b6
commit
f42304c967
1 changed files with 20 additions and 0 deletions
20
bin/cleanup
20
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,
|
||||
|
|
Loading…
Reference in a new issue