From b7b13c1d8b0606416f2b1380d385aa4992b13865 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 27 Aug 2020 12:44:49 +0200 Subject: [PATCH] make migration more robust for cases where attribute definitions don't contain valid values, closes #1207 --- db/migrations/0161__attr_def_short.js | 28 +++++++++++++++++++++++++-- package.json | 4 ++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/db/migrations/0161__attr_def_short.js b/db/migrations/0161__attr_def_short.js index 3e01a97e5..fcccabaf6 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.json index 6a5a0e33e..a445ea453 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",