fix: fkeys on device_id

This commit is contained in:
Rafael Taranto 2024-08-21 13:24:37 +01:00
parent 741eac9484
commit 2b2738c204
3 changed files with 15 additions and 1 deletions

View file

@ -49,6 +49,7 @@ const getDefaultSchema = () => 'ERROR_SCHEMA'
const searchPathWrapper = (t, cb) => { const searchPathWrapper = (t, cb) => {
return t.none('SET search_path TO $1:name', [getSchema()]) return t.none('SET search_path TO $1:name', [getSchema()])
.then(cb.bind(t, t)) .then(cb.bind(t, t))
.catch(logger.error)
.finally(() => t.none('SET search_path TO $1:name', [getDefaultSchema()])) .finally(() => t.none('SET search_path TO $1:name', [getDefaultSchema()]))
} }

View file

@ -32,7 +32,8 @@ function unpair (deviceId) {
const q2 = t.none(`DELETE FROM machine_pings 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 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]) 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])
}) })
) )
} }

View file

@ -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()
}