Merge pull request #954 from josepfo/fix/migration-for-multiple-cassettes-support
fix: skipping queries on migration
This commit is contained in:
commit
4cf330f6fb
2 changed files with 27 additions and 35 deletions
|
|
@ -22,8 +22,6 @@ function getMnemonic () {
|
|||
function generateOperatorId () {
|
||||
return getMnemonic().then(mnemonic => {
|
||||
return computeOperatorId(mnemonicHelpers.toEntropyBuffer(mnemonic))
|
||||
}).then(id => {
|
||||
return id
|
||||
}).catch(e => {
|
||||
console.error('Error while computing operator id\n' + e)
|
||||
throw e
|
||||
|
|
@ -31,27 +29,19 @@ function generateOperatorId () {
|
|||
}
|
||||
|
||||
exports.up = function (next) {
|
||||
const sql =
|
||||
[
|
||||
`CREATE TABLE operator_ids (
|
||||
id serial PRIMARY KEY,
|
||||
operator_id TEXT NOT NULL,
|
||||
service TEXT NOT NULL
|
||||
)`
|
||||
]
|
||||
generateOperatorId()
|
||||
return generateOperatorId()
|
||||
.then(operatorId => {
|
||||
const sql2 = [
|
||||
const sql = [
|
||||
`CREATE TABLE operator_ids (
|
||||
id serial PRIMARY KEY,
|
||||
operator_id TEXT NOT NULL,
|
||||
service TEXT NOT NULL
|
||||
)`,
|
||||
`INSERT INTO operator_ids (operator_id, service) VALUES ('${operatorId}','middleware')`,
|
||||
`INSERT INTO operator_ids (operator_id, service) VALUES ('${operatorId}','coinatmradar')`,
|
||||
`INSERT INTO operator_ids (operator_id, service) VALUES ('${operatorId}','authentication')`
|
||||
]
|
||||
db.multi(sql.concat(sql2), next)
|
||||
.then(() => next())
|
||||
})
|
||||
.catch(e => {
|
||||
db.multi(sql, next)
|
||||
.then(() => next())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,32 +5,35 @@ const { getMachines } = require('../lib/machine-loader')
|
|||
|
||||
exports.up = function (next) {
|
||||
var sql = [
|
||||
'ALTER TABLE devices ADD COLUMN cassette3 INTEGER NOT NULL DEFAULT 0',
|
||||
'ALTER TABLE devices ADD COLUMN cassette4 INTEGER NOT NULL DEFAULT 0',
|
||||
'ALTER TABLE cash_out_txs ADD COLUMN provisioned_3 INTEGER',
|
||||
'ALTER TABLE cash_out_txs ADD COLUMN provisioned_4 INTEGER',
|
||||
'ALTER TABLE cash_out_txs ADD COLUMN denomination_3 INTEGER',
|
||||
'ALTER TABLE cash_out_txs ADD COLUMN denomination_4 INTEGER',
|
||||
'ALTER TABLE cash_out_actions ADD COLUMN provisioned_3 INTEGER',
|
||||
'ALTER TABLE cash_out_actions ADD COLUMN provisioned_4 INTEGER',
|
||||
'ALTER TABLE cash_out_actions ADD COLUMN dispensed_3 INTEGER',
|
||||
'ALTER TABLE cash_out_actions ADD COLUMN dispensed_4 INTEGER',
|
||||
'ALTER TABLE cash_out_actions ADD COLUMN rejected_3 INTEGER',
|
||||
'ALTER TABLE cash_out_actions ADD COLUMN rejected_4 INTEGER',
|
||||
'ALTER TABLE cash_out_actions ADD COLUMN denomination_3 INTEGER',
|
||||
'ALTER TABLE cash_out_actions ADD COLUMN denomination_4 INTEGER',
|
||||
'ALTER TABLE devices ADD COLUMN number_of_cassettes INTEGER NOT NULL DEFAULT 2'
|
||||
`ALTER TABLE cash_out_actions
|
||||
ADD COLUMN provisioned_3 INTEGER,
|
||||
ADD COLUMN provisioned_4 INTEGER,
|
||||
ADD COLUMN dispensed_3 INTEGER,
|
||||
ADD COLUMN dispensed_4 INTEGER,
|
||||
ADD COLUMN rejected_3 INTEGER,
|
||||
ADD COLUMN rejected_4 INTEGER,
|
||||
ADD COLUMN denomination_3 INTEGER,
|
||||
ADD COLUMN denomination_4 INTEGER`,
|
||||
`ALTER TABLE devices
|
||||
ADD COLUMN cassette3 INTEGER NOT NULL DEFAULT 0,
|
||||
ADD COLUMN cassette4 INTEGER NOT NULL DEFAULT 0,
|
||||
ADD COLUMN number_of_cassettes INTEGER NOT NULL DEFAULT 2`,
|
||||
`ALTER TABLE cash_out_txs
|
||||
ADD COLUMN provisioned_3 INTEGER,
|
||||
ADD COLUMN provisioned_4 INTEGER,
|
||||
ADD COLUMN denomination_3 INTEGER,
|
||||
ADD COLUMN denomination_4 INTEGER`
|
||||
]
|
||||
|
||||
return Promise.all([loadLatest(), getMachines()])
|
||||
.then(([config, machines]) => {
|
||||
const formattedMachines = _.map(it => _.pick(['deviceId'], it), machines)
|
||||
const newConfig = _.reduce((acc, value) => {
|
||||
if(_.includes(`cashOut_${value.deviceId}_top`, _.keys(config.config))) {
|
||||
if (_.includes(`cashOut_${value.deviceId}_top`, _.keys(config.config))) {
|
||||
acc[`cashOut_${value.deviceId}_cassette1`] = config.config[`cashOut_${value.deviceId}_top`]
|
||||
}
|
||||
|
||||
if(_.includes(`cashOut_${value.deviceId}_bottom`, _.keys(config.config))) {
|
||||
if (_.includes(`cashOut_${value.deviceId}_bottom`, _.keys(config.config))) {
|
||||
acc[`cashOut_${value.deviceId}_cassette2`] = config.config[`cashOut_${value.deviceId}_bottom`]
|
||||
}
|
||||
|
||||
|
|
@ -39,7 +42,6 @@ exports.up = function (next) {
|
|||
|
||||
return saveConfig(newConfig)
|
||||
.then(() => db.multi(sql, next))
|
||||
.catch(err => next(err))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue