Merge pull request #1063 from josepfo/fix/save-config-breaks-migration
fix: save config used on migration
This commit is contained in:
commit
16cce6fceb
12 changed files with 29 additions and 19 deletions
|
|
@ -82,6 +82,15 @@ function saveConfig (config) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function migrationSaveConfig (config) {
|
||||||
|
return loadLatestConfigOrNone()
|
||||||
|
.then(currentConfig => {
|
||||||
|
const newConfig = _.assign(currentConfig, config)
|
||||||
|
return db.none(configSql, ['config', { config: newConfig }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||||
|
.catch(console.error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function resetConfig (schemaVersion) {
|
function resetConfig (schemaVersion) {
|
||||||
return db.none(
|
return db.none(
|
||||||
configSql,
|
configSql,
|
||||||
|
|
@ -172,6 +181,7 @@ function migrate () {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
saveConfig,
|
saveConfig,
|
||||||
|
migrationSaveConfig,
|
||||||
resetConfig,
|
resetConfig,
|
||||||
saveAccounts,
|
saveAccounts,
|
||||||
resetAccounts,
|
resetAccounts,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const db = require('./db')
|
const db = require('./db')
|
||||||
const machineLoader = require('../lib/machine-loader')
|
const machineLoader = require('../lib/machine-loader')
|
||||||
const { saveConfig, saveAccounts, loadLatest } = require('../lib/new-settings-loader')
|
const { migrationSaveConfig, saveAccounts, loadLatest } = require('../lib/new-settings-loader')
|
||||||
const { migrate } = require('../lib/config-migration')
|
const { migrate } = require('../lib/config-migration')
|
||||||
|
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
|
|
@ -11,7 +11,7 @@ module.exports.up = function (next) {
|
||||||
function migrateConfig (settings) {
|
function migrateConfig (settings) {
|
||||||
const newSettings = migrate(settings.config, settings.accounts)
|
const newSettings = migrate(settings.config, settings.accounts)
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
saveConfig(newSettings.config),
|
migrationSaveConfig(newSettings.config),
|
||||||
saveAccounts(newSettings.accounts)
|
saveAccounts(newSettings.accounts)
|
||||||
])
|
])
|
||||||
.then(() => next())
|
.then(() => next())
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ exports.up = function (next) {
|
||||||
}
|
}
|
||||||
})(deviceIds)
|
})(deviceIds)
|
||||||
|
|
||||||
return settingsLoader.saveConfig(config)
|
return settingsLoader.migrationSaveConfig(config)
|
||||||
})
|
})
|
||||||
.then(() => next())
|
.then(() => next())
|
||||||
.catch(err => next(err))
|
.catch(err => next(err))
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const { saveConfig } = require('../lib/new-settings-loader')
|
const { migrationSaveConfig } = require('../lib/new-settings-loader')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const triggersDefault = {
|
const triggersDefault = {
|
||||||
|
|
@ -6,7 +6,7 @@ exports.up = function (next) {
|
||||||
triggersConfig_automation: 'Automatic'
|
triggersConfig_automation: 'Automatic'
|
||||||
}
|
}
|
||||||
|
|
||||||
return saveConfig(triggersDefault)
|
return migrationSaveConfig(triggersDefault)
|
||||||
.then(() => next())
|
.then(() => next())
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err.message)
|
console.log(err.message)
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ exports.up = async function (next) {
|
||||||
config[key] = 'none'
|
config[key] = 'none'
|
||||||
}
|
}
|
||||||
}, cryptoCodes)
|
}, cryptoCodes)
|
||||||
return settingsLoader.saveConfig(config)
|
return settingsLoader.migrationSaveConfig(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.down = function (next) {
|
exports.down = function (next) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
const { saveConfig, loadLatest } = require('../lib/new-settings-loader')
|
const { migrationSaveConfig, loadLatest } = require('../lib/new-settings-loader')
|
||||||
const { CASSETTE_MAX_CAPACITY } = require('../lib/constants')
|
const { CASSETTE_MAX_CAPACITY } = require('../lib/constants')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
|
|
@ -49,7 +49,7 @@ exports.up = function (next) {
|
||||||
return newOverride
|
return newOverride
|
||||||
}, config.notifications_fiatBalanceOverrides)
|
}, config.notifications_fiatBalanceOverrides)
|
||||||
}
|
}
|
||||||
return saveConfig(newConfig)
|
return migrationSaveConfig(newConfig)
|
||||||
.then(() => next())
|
.then(() => next())
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ exports.up = function (next) {
|
||||||
.then(({ config }) => {
|
.then(({ config }) => {
|
||||||
if (!_.isEmpty(config))
|
if (!_.isEmpty(config))
|
||||||
config.locale_timezone = '0:0'
|
config.locale_timezone = '0:0'
|
||||||
return settingsLoader.saveConfig(config)
|
return settingsLoader.migrationSaveConfig(config)
|
||||||
})
|
})
|
||||||
.then(() => next())
|
.then(() => next())
|
||||||
.catch(err => next(err))
|
.catch(err => next(err))
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const { saveConfig, loadLatest } = require('../lib/new-settings-loader')
|
const { migrationSaveConfig, loadLatest } = require('../lib/new-settings-loader')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const newConfig = {
|
const newConfig = {
|
||||||
|
|
@ -6,7 +6,7 @@ exports.up = function (next) {
|
||||||
}
|
}
|
||||||
return loadLatest()
|
return loadLatest()
|
||||||
.then(config => {
|
.then(config => {
|
||||||
return saveConfig(newConfig)
|
return migrationSaveConfig(newConfig)
|
||||||
.then(() => next())
|
.then(() => next())
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.message === 'lamassu-server is not configured') {
|
if (err.message === 'lamassu-server is not configured') {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
const { saveConfig, loadLatest } = require('../lib/new-settings-loader')
|
const { migrationSaveConfig, loadLatest } = require('../lib/new-settings-loader')
|
||||||
const { getCryptosFromWalletNamespace } = require('../lib/new-config-manager')
|
const { getCryptosFromWalletNamespace } = require('../lib/new-config-manager')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
|
|
@ -8,7 +8,7 @@ exports.up = function (next) {
|
||||||
.then(config => {
|
.then(config => {
|
||||||
const coins = getCryptosFromWalletNamespace(config)
|
const coins = getCryptosFromWalletNamespace(config)
|
||||||
_.map(coin => { newConfig[`wallets_${coin}_feeMultiplier`] = '1' }, coins)
|
_.map(coin => { newConfig[`wallets_${coin}_feeMultiplier`] = '1' }, coins)
|
||||||
return saveConfig(newConfig)
|
return migrationSaveConfig(newConfig)
|
||||||
})
|
})
|
||||||
.then(next)
|
.then(next)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const db = require('./db')
|
const db = require('./db')
|
||||||
const { saveConfig, loadLatest } = require('../lib/new-settings-loader')
|
const { migrationSaveConfig, loadLatest } = require('../lib/new-settings-loader')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql = [
|
const sql = [
|
||||||
|
|
@ -19,7 +19,7 @@ exports.up = function (next) {
|
||||||
newConfig.notifications_notificationCenter_security = true
|
newConfig.notifications_notificationCenter_security = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return saveConfig(newConfig)
|
return migrationSaveConfig(newConfig)
|
||||||
.then(() => db.multi(sql, next))
|
.then(() => db.multi(sql, next))
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
return next(err)
|
return next(err)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
const { saveConfig, loadLatest } = require('../lib/new-settings-loader')
|
const { migrationSaveConfig, loadLatest } = require('../lib/new-settings-loader')
|
||||||
const { getCryptosFromWalletNamespace } = require('../lib/new-config-manager.js')
|
const { getCryptosFromWalletNamespace } = require('../lib/new-config-manager.js')
|
||||||
const { utils: coinUtils } = require('lamassu-coins')
|
const { utils: coinUtils } = require('lamassu-coins')
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
|
|
@ -14,7 +14,7 @@ exports.up = function (next) {
|
||||||
newSettings[`wallets_${crypto}_cryptoUnits`] = defaultUnit
|
newSettings[`wallets_${crypto}_cryptoUnits`] = defaultUnit
|
||||||
return newSettings
|
return newSettings
|
||||||
}, activeCryptos)
|
}, activeCryptos)
|
||||||
return saveConfig(newSettings)
|
return migrationSaveConfig(newSettings)
|
||||||
})
|
})
|
||||||
.then(() => next())
|
.then(() => next())
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
var db = require('./db')
|
var db = require('./db')
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
const { saveConfig, loadLatest } = require('../lib/new-settings-loader')
|
const { migrationSaveConfig, loadLatest } = require('../lib/new-settings-loader')
|
||||||
const { getMachines } = require('../lib/machine-loader')
|
const { getMachines } = require('../lib/machine-loader')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
|
|
@ -40,7 +40,7 @@ exports.up = function (next) {
|
||||||
return acc
|
return acc
|
||||||
}, {}, formattedMachines)
|
}, {}, formattedMachines)
|
||||||
|
|
||||||
return saveConfig(newConfig)
|
return migrationSaveConfig(newConfig)
|
||||||
.then(() => db.multi(sql, next))
|
.then(() => db.multi(sql, next))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue