fix: skipping queries on migration

This commit is contained in:
José Oliveira 2021-11-25 21:03:53 +00:00
parent 1cb715332a
commit 946260480d
2 changed files with 27 additions and 35 deletions

View file

@ -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())
})
}