From 30ac3d61be21022e4b02172936c87c25f19703d0 Mon Sep 17 00:00:00 2001 From: Nikola Ubavic <53820106+ubavic@users.noreply.github.com> Date: Wed, 13 Oct 2021 18:16:57 +0200 Subject: [PATCH] refactor: transaction instead query sequence added query for purging the machine_network_performance table --- lib/pairing.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/pairing.js b/lib/pairing.js index e795e8b1..fdfa52a8 100644 --- a/lib/pairing.js +++ b/lib/pairing.js @@ -13,12 +13,13 @@ function pullToken (token) { } 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. - 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) {