feat: Create migration from old config to new (#424)
* fix: adapt old settings loader to the new schema (filter schema_version) feat: migrate commissions globals feat: migrate locales refactor: generalize the old fields search chore: created functions signatures for all config migrations feat: created wallet migration feat: migrate operator info feat: migrate coin atm radar feat: migrate terms and conditions feat: migrate commissions overrides fix: removed the wallet_COIN_active field (don't exist anymore) chore: moved the config-migration lib to the lib folder feat: migrate cashout configurations feat: migrate notifications globals feat: export migration function feat: migrate most of notifications scoped configs fix: added the missing text property to the terms and conditions migration feat: migrate compliance triggers feat: migrate receipt printing feat: migrate accounts chore: remove test code form module refactor: change some functions naming fix: set default trigger type to 'volume' feat: added threshold days (default 1) to triggers fix: removed strike from the accounts importing refactor: cleaner code on fixed properties feat: avoid repeated crypto/machine pairs on the commissions overrides migrations refactor: make renameAccountFields function internal to the account migration function fix: migrate all crypto scoped commission overrides * fix: return plain objects from functions to make the jsons more readable fix: fix bitgo fields casing fix: improve commissions migration function readability refactor: standard styling * feat: add fallback values to the migration * feat: created db migration for the new config * feat: create migration to move machine names from file to db fix: updates machine names before the config migration fix: load machineLoader fix: create a param to ignore the schema version when loading the latest config using the old loader * refactor: remove unnecessary arguments on createTrigger function fix: check if there's an smsVerificationThreshold configured prior to migrating triggers * fix: migrate triggers with the correct thresholds and verify if they're valid
This commit is contained in:
parent
3c6f547349
commit
ccf7eacfad
8 changed files with 546 additions and 42 deletions
38
migrations/1599523522436-migrate-config.js
Normal file
38
migrations/1599523522436-migrate-config.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const db = require('./db')
|
||||
const settingsLoader = require('../lib/settings-loader')
|
||||
const machineLoader = require('../lib/machine-loader')
|
||||
const { saveConfig, saveAccounts } = require('../lib/new-settings-loader')
|
||||
const { migrate } = require('../lib/config-migration')
|
||||
|
||||
module.exports.up = function (next) {
|
||||
function migrateConfig(settings) {
|
||||
return migrate(settings.config, settings.accounts)
|
||||
.then(newSettings => Promise.all([
|
||||
saveConfig(newSettings.config),
|
||||
saveAccounts(newSettings.accounts)
|
||||
]))
|
||||
.then(() => next())
|
||||
}
|
||||
|
||||
settingsLoader.loadLatest(false)
|
||||
.then(async settings => ({
|
||||
settings,
|
||||
machines: await machineLoader.getMachineNames(settings.config)
|
||||
}))
|
||||
.then(({ settings, machines }) => {
|
||||
const sql = machines
|
||||
? machines.map(m => `update devices set name = '${m.name}' where device_id = '${m.deviceId}'`)
|
||||
: []
|
||||
return db.multi(sql, () => migrateConfig(settings))
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.message = 'lamassu-server is not configured')
|
||||
next()
|
||||
|
||||
console.log(err.message)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.down = function (next) {
|
||||
next()
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ module.exports = {migrateNames}
|
|||
function migrateNames () {
|
||||
const cs = new pgp.helpers.ColumnSet(['?device_id', 'name'], {table: 'devices'})
|
||||
|
||||
return settingsLoader.loadLatest()
|
||||
return settingsLoader.loadLatest(false)
|
||||
.then(r => machineLoader.getMachineNames(r.config))
|
||||
.then(_.map(r => ({device_id: r.deviceId, name: r.name})))
|
||||
.then(data => pgp.helpers.update(data, cs) + ' WHERE t.device_id=v.device_id')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue