fix: sql script
chore: use one query
This commit is contained in:
parent
654e7c601e
commit
b0c3ccdea6
1 changed files with 15 additions and 18 deletions
|
|
@ -17,8 +17,9 @@ function pullToken (token) {
|
|||
return db.one(sql, [token])
|
||||
}
|
||||
|
||||
// TODO new-admin: We should remove all configs related to that device. This can get tricky.
|
||||
function unpair (deviceId) {
|
||||
const backupSQL = `INSERT INTO
|
||||
const sql = `INSERT INTO
|
||||
unpaired_devices(id, device_id, name, model, paired, unpaired)
|
||||
VALUES (
|
||||
$1,
|
||||
|
|
@ -26,17 +27,13 @@ function unpair (deviceId) {
|
|||
(SELECT name FROM devices WHERE device_id=$2),
|
||||
(SELECT model FROM devices WHERE device_id=$2),
|
||||
(SELECT created FROM devices WHERE device_id=$2),
|
||||
now()
|
||||
)`
|
||||
now());
|
||||
DELETE FROM devices WHERE device_id=$2;
|
||||
DELETE FROM machine_pings WHERE device_id=$2;
|
||||
DELETE FROM machine_network_heartbeat WHERE device_id=$2;
|
||||
DELETE FROM machine_network_performance WHERE device_id=$2;`
|
||||
|
||||
// TODO new-admin: We should remove all configs related to that device. This can get tricky.
|
||||
return db.tx(t => {
|
||||
const q1 = t.none('DELETE FROM devices WHERE device_id=$1', [deviceId])
|
||||
const q2 = t.none('DELETE FROM machine_pings WHERE device_id=$1', [deviceId])
|
||||
const q3 = t.none('DELETE FROM machine_network_heartbeat WHERE device_id=$1', [deviceId])
|
||||
const q4 = t.none('DELETE FROM machine_network_performance WHERE device_id=$1', [deviceId])
|
||||
return t.manyOrNone(backupSQL, [uuid.v4(), deviceId]).then(() => Promise.all([q1, q2, q3, q4]))
|
||||
})
|
||||
return db.tx(t => t.none(sql, [uuid.v4(), deviceId]))
|
||||
}
|
||||
|
||||
function pair (token, deviceId, machineModel, numOfCassettes = DEFAULT_NUMBER_OF_CASSETTES) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue