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,26 +17,23 @@ function pullToken (token) {
|
||||||
return db.one(sql, [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) {
|
function unpair (deviceId) {
|
||||||
const backupSQL = `INSERT INTO
|
const sql = `INSERT INTO
|
||||||
unpaired_devices(id, device_id, name, model, paired, unpaired)
|
unpaired_devices(id, device_id, name, model, paired, unpaired)
|
||||||
VALUES (
|
VALUES (
|
||||||
$1,
|
$1,
|
||||||
$2,
|
$2,
|
||||||
(SELECT name FROM devices WHERE device_id=$2),
|
(SELECT name FROM devices WHERE device_id=$2),
|
||||||
(SELECT model FROM devices WHERE device_id=$2),
|
(SELECT model FROM devices WHERE device_id=$2),
|
||||||
(SELECT created 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 => t.none(sql, [uuid.v4(), deviceId]))
|
||||||
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]))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function pair (token, deviceId, machineModel, numOfCassettes = DEFAULT_NUMBER_OF_CASSETTES) {
|
function pair (token, deviceId, machineModel, numOfCassettes = DEFAULT_NUMBER_OF_CASSETTES) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue