Skip to content

Build your personal knowledge base with Trilium Notes

fix migration script in case of not fully consistent database (missing note_contents for note). closes #717

zadamc8ba07a4aecc
diff --git a/db/migrations/0152__add_contentLength_to_note.sql b/db/migrations/0152__add_contentLength_to_note.sql
index 4d4cf0c8c7..60e38df86d 100644
--- a/db/migrations/0152__add_contentLength_to_note.sql
+++ b/db/migrations/0152__add_contentLength_to_note.sql
@@ -20,7 +20,7 @@ SELECT noteId, title, -1, isProtected, type, mime, hash, isDeleted, isErased, da
DROP TABLE notes;
ALTER TABLE notes_mig RENAME TO notes;
-UPDATE notes SET contentLength = (SELECT COALESCE(LENGTH(content), 0) FROM note_contents WHERE note_contents.noteId = notes.noteId);
+UPDATE notes SET contentLength = COALESCE((SELECT COALESCE(LENGTH(content), 0) FROM note_contents WHERE note_contents.noteId = notes.noteId), -1);
CREATE INDEX `IDX_notes_isDeleted` ON `notes` (`isDeleted`);
CREATE INDEX `IDX_notes_title` ON `notes` (`title`);