Feat: config migration
This commit is contained in:
parent
86add28ce6
commit
4681de4033
1 changed files with 40 additions and 0 deletions
40
migrations/1617742522808-zeroConfLimit-migrate.js
Normal file
40
migrations/1617742522808-zeroConfLimit-migrate.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
const _ = require('lodash/fp')
|
||||
var db = require('../lib/db')
|
||||
const settingsLoader = require('../lib/new-settings-loader')
|
||||
const configManager = require('../lib/new-config-manager')
|
||||
|
||||
exports.up = function (next) {
|
||||
db.tx(async t => {
|
||||
let min = Infinity
|
||||
const sp = settingsLoader.loadLatest()
|
||||
const mp = t.any('SELECT device_id FROM devices')
|
||||
const [{ config }, machines] = await Promise.all([sp, mp])
|
||||
const cryptoCurrencies = config.locale_cryptoCurrencies
|
||||
_.forEach(o => {
|
||||
const machineId = o.device_id
|
||||
const cashOutConfig = configManager.getCashOut(machineId, config)
|
||||
const zeroConfLimit = cashOutConfig.zeroConfLimit || Infinity
|
||||
if (zeroConfLimit < min) {
|
||||
min = zeroConfLimit
|
||||
}
|
||||
}, machines)
|
||||
if (min === Infinity) {
|
||||
min = 0
|
||||
}
|
||||
_.forEach(cryptoCode => {
|
||||
const walletConfig = configManager.getWalletSettings(cryptoCode, config)
|
||||
const zeroConfLimit = walletConfig.zeroConfLimit || null
|
||||
const key = `wallets_${cryptoCode}_zeroConfLimit`
|
||||
if (!zeroConfLimit) {
|
||||
config[key] = Number(min)
|
||||
}
|
||||
}, cryptoCurrencies)
|
||||
return settingsLoader.saveConfig(config)
|
||||
})
|
||||
.then(() => next())
|
||||
.catch(err => next(err))
|
||||
}
|
||||
|
||||
exports.down = function (next) {
|
||||
next()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue