Truncate/trim server tables

This commit is contained in:
Rafael Taranto 2019-04-24 23:05:39 -03:00 committed by Josh Harvey
parent 4640b4a774
commit 67919892e8
5 changed files with 35 additions and 17 deletions

View file

@ -54,6 +54,14 @@ function update (deviceId, logLines) {
return _.mapKeys(_.snakeCase, formatted)
}, logLines)
const sql = pgp.helpers.insert(logs, cs) + 'on conflict do nothing'
return db.none(sql)
}
function clearOldLogs () {
const sql = `delete from logs
where timestamp < now() - interval '3 days'`
return db.none(sql)
}
@ -87,4 +95,4 @@ function getMachineLogs (deviceId, until = new Date().toISOString()) {
}))
}
module.exports = { getUnlimitedMachineLogs, getMachineLogs, update, getLastSeen }
module.exports = { getUnlimitedMachineLogs, getMachineLogs, update, getLastSeen, clearOldLogs }