diff --git a/lib/db.js b/lib/db.js index 6dc9778a..561e4fc6 100644 --- a/lib/db.js +++ b/lib/db.js @@ -49,6 +49,7 @@ const getDefaultSchema = () => 'ERROR_SCHEMA' const searchPathWrapper = (t, cb) => { return t.none('SET search_path TO $1:name', [getSchema()]) .then(cb.bind(t, t)) + .catch(logger.error) .finally(() => t.none('SET search_path TO $1:name', [getDefaultSchema()])) } diff --git a/lib/pairing.js b/lib/pairing.js index 72e88f4c..ebedc001 100644 --- a/lib/pairing.js +++ b/lib/pairing.js @@ -32,7 +32,8 @@ function unpair (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.batch([q1, q2, q3, q4]) + const q5 = t.none(`DELETE FROM machine_diagnostics WHERE device_id=$1`, [deviceId]) + return t.batch([q1, q2, q3, q4, q5]) }) ) } diff --git a/migrations/1724242113482-drop-last-used-fkey.js b/migrations/1724242113482-drop-last-used-fkey.js new file mode 100644 index 00000000..3c3b62d7 --- /dev/null +++ b/migrations/1724242113482-drop-last-used-fkey.js @@ -0,0 +1,12 @@ +const db = require('./db') + +exports.up = function (next) { + db.multi([ + 'ALTER TABLE customers DROP CONSTRAINT customers_last_used_machine_fkey;', + 'ALTER TABLE machine_diagnostics DROP CONSTRAINT machine_diagnostics_device_id_fkey;' + ], next) +} + +exports.down = function (next) { + next() +}