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
make migration more robust for cases where attribute definitions don't contain valid values, closes #1207
zadamb7b13c1d8b06
diff --git a/db/migrations/0161__attr_def_short.js b/db/migrations/0161__attr_def_short.jsindex 3e01a97e57..fcccabaf65 100644--- a/db/migrations/0161__attr_def_short.js+++ b/db/migrations/0161__attr_def_short.js@@ -2,7 +2,19 @@ const sql = require('../../src/services/sql');module.exports = () => {for (const attr of sql.getRows("SELECT * FROM attributes WHERE name LIKE 'label:%'")) {- const obj = JSON.parse(attr.value);+ let obj;++ try {+ obj = JSON.parse(attr.value);+ }+ catch (e) {+ console.log(`Parsing attribute definition "${attr.value}" of ${attr.attributeId} failed with error "${e.message}", setting to default value.`);++ sql.execute('UPDATE attributes SET value = ? WHERE attributeId = ?',+ ["multi,text", attr.attributeId]);++ continue;+ }const tokens = [];@@ -30,7 +42,19 @@ module.exports = () => {}for (const attr of sql.getRows("SELECT * FROM attributes WHERE name LIKE 'relation:%'")) {- const obj = JSON.parse(attr.value);+ let obj;++ try {+ obj = JSON.parse(attr.value);+ }+ catch (e) {+ console.log(`Parsing attribute definition "${attr.value}" of ${attr.attributeId} failed with error "${e.message}", setting to default value.`);++ sql.execute('UPDATE attributes SET value = ? WHERE attributeId = ?',+ ["multi", attr.attributeId]);++ continue;+ }const tokens = [];diff --git a/package.json b/package.jsonindex 6a5a0e33ee..a445ea453b 100644--- a/package.json+++ b/package.json@@ -41,7 +41,7 @@"electron-window-state": "5.0.3","express": "4.17.1","express-session": "1.17.1",- "file-type": "14.7.1",+ "file-type": "15.0.0","fs-extra": "9.0.1","helmet": "4.1.0","html": "1.0.0",@@ -62,7 +62,7 @@"request": "^2.88.2","rimraf": "3.0.2","sanitize-filename": "1.6.3",- "sanitize-html": "1.27.3",+ "sanitize-html": "1.27.4","sax": "1.2.4","semver": "7.3.2","serve-favicon": "2.5.0",