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
migration fixes
zadam0ddaa8f5c27a
diff --git a/db/migrations/0198__randomize_branchIds.sql b/db/migrations/0198__randomize_branchIds.sqldeleted file mode 100644index 4e5a1bfe46..0000000000--- a/db/migrations/0198__randomize_branchIds.sql+++ /dev/null@@ -1,7 +0,0 @@--- "randomize" branchIds so it's clear user should not rely on them-UPDATE branches SET branchId = '7LSsI2FnZPW2' WHERE parentNoteId = 'hidden' AND noteId = 'search';-UPDATE branches SET branchId = 'wEcmxk4CNC7G' WHERE parentNoteId = 'singles' AND noteId = 'globalnotemap';-UPDATE branches SET branchId = '191uVR6Cu6fA' WHERE parentNoteId = 'hidden' AND noteId = 'sqlconsole';-UPDATE branches SET branchId = 'OjX5Phxp6A4N' WHERE parentNoteId = 'root' AND noteId = 'hidden';-UPDATE branches SET branchId = 'glNBYFYZRH8P' WHERE parentNoteId = 'hidden' AND noteId = 'bulkaction';-UPDATE branches SET branchId = 'cAT25wvGMg3K' WHERE parentNoteId = 'root' AND noteId = 'share';diff --git a/db/migrations/0198__rename_branchIds.sql b/db/migrations/0198__rename_branchIds.sqlnew file mode 100644index 0000000000..3c6cd0e64a--- /dev/null+++ b/db/migrations/0198__rename_branchIds.sql@@ -0,0 +1,6 @@+UPDATE branches SET branchId = '_hidden__search' WHERE parentNoteId = 'hidden' AND noteId = 'search';+UPDATE branches SET branchId = 'root__globalNoteMap' WHERE parentNoteId = 'singles' AND noteId = 'globalnotemap';+UPDATE branches SET branchId = '_hidden__sqlConsole' WHERE parentNoteId = 'hidden' AND noteId = 'sqlconsole';+UPDATE branches SET branchId = 'root__hidden' WHERE parentNoteId = 'root' AND noteId = 'hidden';+UPDATE branches SET branchId = '_hidden__bulkAction' WHERE parentNoteId = 'hidden' AND noteId = 'bulkaction';+UPDATE branches SET branchId = '_hidden__share' WHERE parentNoteId = 'root' AND noteId = 'share';diff --git a/db/migrations/0202__move_global_note_map_under_hidden.sql b/db/migrations/0202__move_global_note_map_under_hidden.sqlindex 5c5f42812e..0b634f69f8 100644--- a/db/migrations/0202__move_global_note_map_under_hidden.sql+++ b/db/migrations/0202__move_global_note_map_under_hidden.sql@@ -1,2 +1,2 @@-DELETE FROM branches WHERE noteId = '_globalNoteMap' AND parentNoteId != 'singles'; -- make sure there are no clones which would fail at the next line+DELETE FROM branches WHERE noteId = '_globalNoteMap' AND parentNoteId != 'singles' AND parentNoteId != '_hidden'; -- make sure there are no clones which would fail at the next lineUPDATE branches SET parentNoteId = '_hidden' WHERE noteId = '_globalNoteMap';diff --git a/src/becca/entities/branch.js b/src/becca/entities/branch.jsindex 27f6babe9c..cd647775e0 100644--- a/src/becca/entities/branch.js+++ b/src/becca/entities/branch.js@@ -232,6 +232,10 @@ class Branch extends AbstractEntity {this.isExpanded = false;}+ if (!this.prefix?.trim()) {+ this.prefix = null;+ }+this.utcDateModified = dateUtils.utcNowDateTime();super.beforeSaving();diff --git a/src/services/cloning.js b/src/services/cloning.jsindex 8f5952ca0e..e7a977edfb 100644--- a/src/services/cloning.js+++ b/src/services/cloning.js@@ -78,14 +78,14 @@ function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {return validationResult;}- new Branch({+ const branch = new Branch({noteId: noteId,parentNoteId: parentNoteId,prefix: prefix,isExpanded: 0}).save();- log.info(`Ensured note '${noteId}' is in parent note '${parentNoteId}' with prefix '${prefix}'`);+ log.info(`Ensured note '${noteId}' is in parent note '${parentNoteId}' with prefix '${branch.prefix}'`);return { success: true };}diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.jsindex 85e401da91..483048d19c 100644--- a/src/services/consistency_checks.js+++ b/src/services/consistency_checks.js@@ -296,7 +296,7 @@ class ConsistencyChecks {for (const branch of branches.slice(1)) {branch.markAsDeleted();- logFix(`Removing branch '${branch.branchId}' since it's parent-child duplicate of branch '${origBranch.branchId}'`);+ logFix(`Removing branch '${branch.branchId}' since it's a parent-child duplicate of branch '${origBranch.branchId}'`);}this.reloadNeeded = true;diff --git a/src/services/hidden_subtree.js b/src/services/hidden_subtree.jsindex a3113381df..b6be8d619c 100644--- a/src/services/hidden_subtree.js+++ b/src/services/hidden_subtree.js@@ -244,7 +244,7 @@ function checkHiddenSubtreeRecursively(parentNoteId, item) {}let note = becca.notes[item.id];- let branch = becca.branches[item.id];+ let branch;if (!note) {({note, branch} = noteService.createNewNote({@@ -255,6 +255,8 @@ function checkHiddenSubtreeRecursively(parentNoteId, item) {content: '',ignoreForbiddenParents: true}));+ } else {+ branch = note.getParentBranches().find(branch => branch.parentNoteId === parentNoteId);}const attrs = [...(item.attributes || [])];diff --git a/src/services/migration.js b/src/services/migration.jsindex f73b0f3e23..1bda273e49 100644--- a/src/services/migration.js+++ b/src/services/migration.js@@ -22,7 +22,7 @@ async function migrate() {}fs.readdirSync(resourceDir.MIGRATIONS_DIR).forEach(file => {- const match = file.match(/([0-9]{4})__([a-zA-Z0-9_ ]+)\.(sql|js)/);+ const match = file.match(/^([0-9]{4})__([a-zA-Z0-9_ ]+)\.(sql|js)$/);if (match) {const dbVersion = parseInt(match[1]);