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(core): sweep stale _help entity_changes in migration; skip virtual notes when protecting
Claude7b4a486df1f7
diff --git a/packages/trilium-core/src/migrations/migrations.ts b/packages/trilium-core/src/migrations/migrations.tsindex 811aa4e196..8b9e808694 100644--- a/packages/trilium-core/src/migrations/migrations.ts+++ b/packages/trilium-core/src/migrations/migrations.ts@@ -29,8 +29,11 @@ export const MIGRATIONS: (SqlMigration | JsMigration)[] = [(SELECT revisionId FROM revisions WHERE noteId LIKE '\\_help%' ESCAPE '\\');DELETE FROM entity_changes WHERE entityName = 'attachments' AND entityId IN(SELECT attachmentId FROM attachments WHERE ownerId LIKE '\\_help%' ESCAPE '\\');- DELETE FROM entity_changes WHERE entityName = 'notes' AND entityId LIKE '\\_help%' ESCAPE '\\';- DELETE FROM entity_changes WHERE entityName = 'note_reordering' AND entityId LIKE '\\_help%' ESCAPE '\\';+ -- Blanket sweep by ID prefix: catches notes and note_reordering rows directly, plus+ -- tombstones of help branches/attributes deleted (and later erased) by past releases —+ -- their base rows are gone, so the subselects above cannot find them, but branch IDs+ -- ('parentNoteId_noteId') and attribute IDs ('noteId_...') carry the _help prefix.+ DELETE FROM entity_changes WHERE entityId LIKE '\\_help%' ESCAPE '\\';DELETE FROM branches WHERE noteId LIKE '\\_help%' ESCAPE '\\' OR parentNoteId LIKE '\\_help%' ESCAPE '\\';DELETE FROM attributes WHERE noteId LIKE '\\_help%' ESCAPE '\\';DELETE FROM revisions WHERE noteId LIKE '\\_help%' ESCAPE '\\';diff --git a/packages/trilium-core/src/services/notes.ts b/packages/trilium-core/src/services/notes.tsindex 6492fd20a7..78f04dc2b8 100644--- a/packages/trilium-core/src/services/notes.ts+++ b/packages/trilium-core/src/services/notes.ts@@ -390,6 +390,13 @@ function createNewNoteWithTarget(target: "into" | "after" | "before", targetBran}function protectNoteRecursively(note: BNote, protect: boolean, includingSubTree: boolean, taskContext: TaskContext<"protectNotes">) {+ if (note.isVirtual) {+ // Virtual notes (e.g. the in-app help) are read-only, application-owned and never+ // persisted — (un)protecting them is meaningless. Their children are virtual too,+ // so the whole subtree is skipped.+ return;+ }+protectNote(note, protect);taskContext.increaseProgressCount();