From 56332dfd5b8b10d5f7f5a2343a74ce183ef6842a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Tue, 4 May 2021 21:33:28 +0100 Subject: [PATCH] fix: check for empty user config before migrate --- migrations/1599523522436-migrate-config.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/migrations/1599523522436-migrate-config.js b/migrations/1599523522436-migrate-config.js index ec0bae3b..75d3c954 100644 --- a/migrations/1599523522436-migrate-config.js +++ b/migrations/1599523522436-migrate-config.js @@ -3,6 +3,8 @@ const machineLoader = require('../lib/machine-loader') const { saveConfig, saveAccounts, loadLatest } = require('../lib/new-settings-loader') const { migrate } = require('../lib/config-migration') +const _ = require('lodash/fp') + const OLD_SETTINGS_LOADER_SCHEMA_VERSION = 1 module.exports.up = function (next) { @@ -16,11 +18,22 @@ module.exports.up = function (next) { } loadLatest(OLD_SETTINGS_LOADER_SCHEMA_VERSION) - .then(async settings => ({ - settings, - machines: await machineLoader.getMachineNames(settings.config) - })) + .then(async settings => { + if (_.isEmpty(settings.config)) { + return { + settings, + machines: [] + } + } + return { + settings, + machines: await machineLoader.getMachineNames(settings.config) + } + }) .then(({ settings, machines }) => { + if (_.isEmpty(settings.config)) { + return next() + } const sql = machines ? machines.map(m => `update devices set name = '${m.name}' where device_id = '${m.deviceId}'`) : []