migration fixes

This commit is contained in:
zadam 2022-12-27 21:17:40 +01:00
parent 620bed73bb
commit 0ddaa8f5c2
8 changed files with 18 additions and 13 deletions

View File

@ -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';

View File

@ -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';

View File

@ -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'; UPDATE branches SET parentNoteId = '_hidden' WHERE noteId = '_globalNoteMap';

View File

@ -232,6 +232,10 @@ class Branch extends AbstractEntity {
this.isExpanded = false; this.isExpanded = false;
} }
if (!this.prefix?.trim()) {
this.prefix = null;
}
this.utcDateModified = dateUtils.utcNowDateTime(); this.utcDateModified = dateUtils.utcNowDateTime();
super.beforeSaving(); super.beforeSaving();

View File

@ -78,14 +78,14 @@ function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {
return validationResult; return validationResult;
} }
new Branch({ const branch = new Branch({
noteId: noteId, noteId: noteId,
parentNoteId: parentNoteId, parentNoteId: parentNoteId,
prefix: prefix, prefix: prefix,
isExpanded: 0 isExpanded: 0
}).save(); }).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 }; return { success: true };
} }

View File

@ -296,7 +296,7 @@ class ConsistencyChecks {
for (const branch of branches.slice(1)) { for (const branch of branches.slice(1)) {
branch.markAsDeleted(); 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; this.reloadNeeded = true;

View File

@ -244,7 +244,7 @@ function checkHiddenSubtreeRecursively(parentNoteId, item) {
} }
let note = becca.notes[item.id]; let note = becca.notes[item.id];
let branch = becca.branches[item.id]; let branch;
if (!note) { if (!note) {
({note, branch} = noteService.createNewNote({ ({note, branch} = noteService.createNewNote({
@ -255,6 +255,8 @@ function checkHiddenSubtreeRecursively(parentNoteId, item) {
content: '', content: '',
ignoreForbiddenParents: true ignoreForbiddenParents: true
})); }));
} else {
branch = note.getParentBranches().find(branch => branch.parentNoteId === parentNoteId);
} }
const attrs = [...(item.attributes || [])]; const attrs = [...(item.attributes || [])];

View File

@ -22,7 +22,7 @@ async function migrate() {
} }
fs.readdirSync(resourceDir.MIGRATIONS_DIR).forEach(file => { 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) { if (match) {
const dbVersion = parseInt(match[1]); const dbVersion = parseInt(match[1]);