fix: check for empty user config before migrate

This commit is contained in:
José Oliveira 2021-05-04 21:33:28 +01:00 committed by Josh Harvey
parent f050f1b8c9
commit 56332dfd5b

View file

@ -3,6 +3,8 @@ const machineLoader = require('../lib/machine-loader')
const { saveConfig, saveAccounts, loadLatest } = require('../lib/new-settings-loader') const { saveConfig, saveAccounts, loadLatest } = require('../lib/new-settings-loader')
const { migrate } = require('../lib/config-migration') const { migrate } = require('../lib/config-migration')
const _ = require('lodash/fp')
const OLD_SETTINGS_LOADER_SCHEMA_VERSION = 1 const OLD_SETTINGS_LOADER_SCHEMA_VERSION = 1
module.exports.up = function (next) { module.exports.up = function (next) {
@ -16,11 +18,22 @@ module.exports.up = function (next) {
} }
loadLatest(OLD_SETTINGS_LOADER_SCHEMA_VERSION) loadLatest(OLD_SETTINGS_LOADER_SCHEMA_VERSION)
.then(async settings => ({ .then(async settings => {
settings, if (_.isEmpty(settings.config)) {
machines: await machineLoader.getMachineNames(settings.config) return {
})) settings,
machines: []
}
}
return {
settings,
machines: await machineLoader.getMachineNames(settings.config)
}
})
.then(({ settings, machines }) => { .then(({ settings, machines }) => {
if (_.isEmpty(settings.config)) {
return next()
}
const sql = machines const sql = machines
? machines.map(m => `update devices set name = '${m.name}' where device_id = '${m.deviceId}'`) ? machines.map(m => `update devices set name = '${m.name}' where device_id = '${m.deviceId}'`)
: [] : []