mirror of
https://github.com/zadam/trilium.git
synced 2025-11-18 03:00:41 +01:00
added some consistency checks for links and attributes
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
const build = require('./build');
|
||||
const packageJson = require('../../package');
|
||||
|
||||
const APP_DB_VERSION = 115;
|
||||
const APP_DB_VERSION = 116;
|
||||
const SYNC_VERSION = 2;
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -219,6 +219,65 @@ async function runAllChecks() {
|
||||
type == 'search'`,
|
||||
"Search note has children", errorList);
|
||||
|
||||
await fixEmptyRelationTargets(errorList);
|
||||
|
||||
await runCheck(`
|
||||
SELECT
|
||||
attributeId
|
||||
FROM
|
||||
attributes
|
||||
WHERE
|
||||
type != 'label'
|
||||
AND type != 'label-definition'
|
||||
AND type != 'relation'
|
||||
AND type != 'relation-definition'`,
|
||||
"Attribute has invalid type", errorList);
|
||||
|
||||
await runCheck(`
|
||||
SELECT
|
||||
attributeId
|
||||
FROM
|
||||
attributes
|
||||
LEFT JOIN notes ON attributes.noteId = notes.noteId AND notes.isDeleted = 0
|
||||
WHERE
|
||||
attributes.isDeleted = 0
|
||||
AND notes.noteId IS NULL`,
|
||||
"Attribute reference to the owning note is broken", errorList);
|
||||
|
||||
await runCheck(`
|
||||
SELECT
|
||||
attributeId
|
||||
FROM
|
||||
attributes
|
||||
LEFT JOIN notes AS targetNote ON attributes.value = targetNote.noteId AND targetNote.isDeleted = 0
|
||||
WHERE
|
||||
attributes.type = 'relation'
|
||||
AND attributes.isDeleted = 0
|
||||
AND targetNote.noteId IS NULL`,
|
||||
"Relation reference to the target note is broken", errorList);
|
||||
|
||||
await runCheck(`
|
||||
SELECT
|
||||
linkId
|
||||
FROM
|
||||
links
|
||||
WHERE
|
||||
type != 'image'
|
||||
AND type != 'hyper'`,
|
||||
"Link type is invalid", errorList);
|
||||
|
||||
await runCheck(`
|
||||
SELECT
|
||||
linkId
|
||||
FROM
|
||||
links
|
||||
LEFT JOIN notes AS sourceNote ON sourceNote.noteId = links.noteId AND sourceNote.isDeleted = 0
|
||||
LEFT JOIN notes AS targetNote ON targetNote.noteId = links.noteId AND targetNote.isDeleted = 0
|
||||
WHERE
|
||||
sourceNote.noteId IS NULL
|
||||
OR targetNote.noteId IS NULL`,
|
||||
"Link to source/target note link is broken", errorList);
|
||||
|
||||
await runSyncRowChecks("notes", "noteId", errorList);
|
||||
await runSyncRowChecks("note_revisions", "noteRevisionId", errorList);
|
||||
await runSyncRowChecks("branches", "branchId", errorList);
|
||||
@@ -233,8 +292,6 @@ async function runAllChecks() {
|
||||
await checkTreeCycles(errorList);
|
||||
}
|
||||
|
||||
await fixEmptyRelationTargets(errorList);
|
||||
|
||||
return errorList;
|
||||
}
|
||||
|
||||
|
||||
@@ -332,9 +332,19 @@ async function deleteNote(branch) {
|
||||
await attribute.save();
|
||||
}
|
||||
|
||||
for (const attribute of await note.getTargetRelations()) {
|
||||
attribute.isDeleted = true;
|
||||
await attribute.save();
|
||||
for (const relation of await note.getTargetRelations()) {
|
||||
relation.isDeleted = true;
|
||||
await relation.save();
|
||||
}
|
||||
|
||||
for (const link of await note.getLinks()) {
|
||||
link.isDeleted = true;
|
||||
await link.save();
|
||||
}
|
||||
|
||||
for (const link of await note.getTargetLinks()) {
|
||||
link.isDeleted = true;
|
||||
await link.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user