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:
Liordino Neto 2020-09-25 07:07:47 -03:00 committed by GitHub
parent 3c6f547349
commit ccf7eacfad
8 changed files with 546 additions and 42 deletions

View file

@ -54,8 +54,8 @@ function load (versionId) {
}))
}
function loadLatest () {
return Promise.all([loadLatestConfig(), loadAccounts()])
function loadLatest (filterSchemaVersion = true) {
return Promise.all([loadLatestConfig(filterSchemaVersion), loadAccounts(filterSchemaVersion)])
.then(([config, accounts]) => ({
config,
accounts
@ -67,10 +67,10 @@ function loadConfig (versionId) {
const sql = `select data
from user_config
where id=$1 and type=$2
where id=$1 and type=$2 and schema_version=$3
and valid`
return db.one(sql, [versionId, 'config'])
return db.one(sql, [versionId, 'config', configValidate.SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => row.data.config)
.then(configValidate.validate)
.catch(err => {
@ -82,17 +82,17 @@ function loadConfig (versionId) {
})
}
function loadLatestConfig () {
function loadLatestConfig (filterSchemaVersion = true) {
if (argv.fixture) return loadFixture()
const sql = `select id, valid, data
from user_config
where type=$1
where type=$1 ${filterSchemaVersion ? 'and schema_version=$2' : ''}
and valid
order by id desc
limit 1`
return db.one(sql, ['config'])
return db.one(sql, ['config', configValidate.SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => row.data.config)
.then(configValidate.validate)
.catch(err => {
@ -109,19 +109,19 @@ function loadRecentConfig () {
const sql = `select id, data
from user_config
where type=$1
where type=$1 and schema_version=$2
order by id desc
limit 1`
return db.one(sql, ['config'])
return db.one(sql, ['config', configValidate.SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => row.data.config)
}
function loadAccounts () {
function loadAccounts (filterSchemaVersion = true) {
const toFields = fieldArr => _.fromPairs(_.map(r => [r.code, r.value], fieldArr))
const toPairs = r => [r.code, toFields(r.fields)]
return db.oneOrNone('select data from user_config where type=$1', 'accounts')
return db.oneOrNone(`select data from user_config where type=$1 ${filterSchemaVersion ? 'and schema_version=$2' : ''}`, ['accounts', configValidate.SETTINGS_LOADER_SCHEMA_VERSION])
.then(function (data) {
if (!data) return {}
return _.fromPairs(_.map(toPairs, data.data.accounts))