Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix note revision's isErased initial value after migration
zadam4ba7e74b5891
diff --git a/db/migrations/0153__add_isErased_to_note_revision.sql b/db/migrations/0153__add_isErased_to_note_revision.sqlindex 0327d251cc..7d35590880 100644--- a/db/migrations/0153__add_isErased_to_note_revision.sql+++ b/db/migrations/0153__add_isErased_to_note_revision.sql@@ -19,6 +19,8 @@ SELECT noteRevisionId, noteId, title, contentLength, 0, isProtected, utcDateLastDROP TABLE note_revisions;ALTER TABLE note_revisions_mig RENAME TO note_revisions;+UPDATE note_revisions SET isErased = (SELECT isErased FROM notes WHERE notes.noteId = note_revisions.noteId);+CREATE INDEX `IDX_note_revisions_noteId` ON `note_revisions` (`noteId`);CREATE INDEX `IDX_note_revisions_utcDateCreated` ON `note_revisions` (`utcDateCreated`);CREATE INDEX `IDX_note_revisions_utcDateLastEdited` ON `note_revisions` (`utcDateLastEdited`);diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex 6d781f7a0e..4819b5157a 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -334,6 +334,27 @@ async function findLogicIssues() {AND content IS NOT NULL`,({noteId}) => `Note ${noteId} content is not null even though the note is erased`);+ await findAndFixIssues(`+ SELECT noteId, noteRevisionId+ FROM notes+ JOIN note_revisions USING(noteId)+ WHERE+ notes.isErased = 1+ AND note_revisions.isErased = 0`,+ async ({noteId, noteRevisionId}, autoFix) => {+ if (autoFix) {+ const noteRevision = await repository.getNoteRevision(noteRevisionId);+ noteRevision.isErased = true;+ await noteRevision.setContent(null);+ await noteRevision.save();++ logFix(`Note revision ${noteRevisionId} has been erased since its note ${noteId} is also erased.`);+ }+ else {+ logError(`Note revision ${noteRevisionId} is not erased even though note ${noteId} is erased.`);+ }+ });+await findAndFixIssues(`SELECT noteRevisionIdFROM note_revisions