refactor: transaction instead query sequence
added query for purging the machine_network_performance table
This commit is contained in:
parent
0288b6b5c0
commit
30ac3d61be
1 changed files with 6 additions and 5 deletions
|
|
@ -13,12 +13,13 @@ function pullToken (token) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function unpair (deviceId) {
|
function unpair (deviceId) {
|
||||||
const sql = 'delete from devices where device_id=$1'
|
|
||||||
const deleteMachinePings = 'delete from machine_pings where device_id=$1'
|
|
||||||
const deleteMachineHeartbeat = 'delete from machine_network_heartbeat where device_id=$1'
|
|
||||||
|
|
||||||
// TODO new-admin: We should remove all configs related to that device. This can get tricky.
|
// TODO new-admin: We should remove all configs related to that device. This can get tricky.
|
||||||
return Promise.all([db.none(sql, [deviceId]), db.none(deleteMachinePings, [deviceId]), db.none(deleteMachineHeartbeat, [deviceId])])
|
return db.tx(async t => {
|
||||||
|
await t.none('DELETE FROM devices WHERE device_id=$1', [deviceId])
|
||||||
|
await t.none('DELETE FROM machine_pings WHERE device_id=$1', [deviceId])
|
||||||
|
await t.none('DELETE FROM machine_network_heartbeat WHERE device_id=$1', [deviceId])
|
||||||
|
await t.none('DELETE FROM machine_network_performance WHERE device_id=$1', [deviceId])
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function pair (token, deviceId, machineModel) {
|
function pair (token, deviceId, machineModel) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue