From 0ddaa8f5c27a297c8bc8097d50b78db8895b9da3 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 27 Dec 2022 21:17:40 +0100 Subject: [PATCH] migration fixes --- db/migrations/0198__randomize_branchIds.sql | 7 ------- db/migrations/0198__rename_branchIds.sql | 6 ++++++ db/migrations/0202__move_global_note_map_under_hidden.sql | 2 +- src/becca/entities/branch.js | 4 ++++ src/services/cloning.js | 4 ++-- src/services/consistency_checks.js | 2 +- src/services/hidden_subtree.js | 4 +++- src/services/migration.js | 2 +- 8 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 db/migrations/0198__randomize_branchIds.sql create mode 100644 db/migrations/0198__rename_branchIds.sql diff --git a/db/migrations/0198__randomize_branchIds.sql b/db/migrations/0198__randomize_branchIds.sql deleted file mode 100644 index 4e5a1bfe4..000000000 --- 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.sql new file mode 100644 index 000000000..3c6cd0e64 --- /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.sql index 5c5f42812..0b634f69f 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 line UPDATE branches SET parentNoteId = '_hidden' WHERE noteId = '_globalNoteMap'; diff --git a/src/becca/entities/branch.js b/src/becca/entities/branch.js index 27f6babe9..cd647775e 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.js index 8f5952ca0..e7a977edf 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.js index 85e401da9..483048d19 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.js index a3113381d..b6be8d619 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.js index f73b0f3e2..1bda273e4 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]);