Skip to content

Commit

Permalink
fix: fkeys on device_id
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelTaranto committed Aug 21, 2024
1 parent 1f5b71f commit 82de800
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()]))
}

Expand Down
3 changes: 2 additions & 1 deletion lib/pairing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
})
)
}
Expand Down
12 changes: 12 additions & 0 deletions migrations/1724242113482-drop-last-used-fkey.js
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 82de800

Please sign in to comment.