Chore: refactor to use new schema changing queries

This commit is contained in:
csrapr 2021-03-01 15:55:29 +00:00 committed by Josh Harvey
parent 304f792484
commit e6059be8d2
44 changed files with 185 additions and 171 deletions

View file

@ -5,11 +5,11 @@ var psqlUrl = require('../lib/options').postgresql
var db = pgp(psqlUrl)
db.manyOrNone(`select * from transactions where incoming=false
db.$manyOrNone(`select * from transactions where incoming=false
and stage='final_request' and authority='machine'`)
.then(rs =>
db.tx(t =>
t.batch(rs.map(r => db.none(`insert into cash_in_txs (session_id,
t.batch(rs.map(r => db.$none(`insert into cash_in_txs (session_id,
device_fingerprint, to_address, crypto_atoms, crypto_code, fiat,
currency_code, fee, tx_hash, error, created) values ($1, $2, $3, $4, $5,
$6, $7, $8, $9, $10, $11)`, [r.session_id, r.device_fingerprint,
@ -18,11 +18,11 @@ db.manyOrNone(`select * from transactions where incoming=false
)
)
)
.then(() => db.manyOrNone(`select * from transactions where incoming=true
.then(() => db.$manyOrNone(`select * from transactions where incoming=true
and stage='initial_request' and authority='pending'`))
.then(rs =>
db.tx(t =>
t.batch(rs.map(r => db.none(`insert into cash_out_txs (session_id,
t.batch(rs.map(r => db.$none(`insert into cash_out_txs (session_id,
device_fingerprint, to_address, crypto_atoms, crypto_code, fiat,
currency_code, tx_hash, phone, error, created) values ($1, $2, $3, $4, $5,
$6, $7, $8, $9, $10, $11)`, [r.session_id, r.device_fingerprint,
@ -31,13 +31,13 @@ db.manyOrNone(`select * from transactions where incoming=false
)
)
)
.then(() => db.manyOrNone(`select * from transactions where incoming=true
.then(() => db.$manyOrNone(`select * from transactions where incoming=true
and stage='dispense' and authority='authorized'`))
.then(rs =>
db.tx(t =>
t.batch(rs.map(r =>
db.none(`update cash_out_txs set dispensed=true where session_id=$1`, [r.session_id])
.then(() => db.none(`insert into cash_out_actions (session_id, action,
db.$none(`update cash_out_txs set dispensed=true where session_id=$1`, [r.session_id])
.then(() => db.$none(`insert into cash_out_actions (session_id, action,
created) values ($1, $2, $3)`, [r.session_id, 'dispensed', r.created]))
))
)

View file

@ -7,7 +7,7 @@ const psqlUrl = require('../lib/options').postgresql
const db = pgp(psqlUrl)
db.many('select data from user_config', 'exchanges')
db.$many('select data from user_config', 'exchanges')
.then(rows => {
const config = rows.filter(r => r.type === 'exchanges')[0].data
const brain = rows.filter(r => r.type === 'unit')[0].data
@ -33,7 +33,7 @@ db.many('select data from user_config', 'exchanges')
accounts: settings.plugins.settings
}
db.none('insert into user_config (type, data) values ($1, $2)', ['global', newConfig])
db.$none('insert into user_config (type, data) values ($1, $2)', ['global', newConfig])
.then(() => {
console.log('Success.')
process.exit(0)