This commit is contained in:
Mateusz Gruszczyński
2026-08-24 15:20:29 +02:00
parent 4f70e36e89
commit 83f744e2cb
19 changed files with 744 additions and 176 deletions
+12
View File
@@ -469,6 +469,12 @@ impl Db {
rows.collect::<std::result::Result<Vec<_>, _>>().map_err(Into::into)
}
pub fn prune_events(&self, retention_days: i64) -> Result<u64> {
let before = Utc::now() - Duration::days(retention_days.max(1));
let conn = self.lock()?;
Ok(conn.execute(queries::PRUNE_EVENTS, [before.to_rfc3339()])? as u64)
}
pub fn list_api_tokens(&self) -> Result<Vec<ApiTokenInfo>> {
let conn = self.lock()?;
let mut stmt = conn.prepare(queries::LIST_API_TOKENS)?;
@@ -601,6 +607,12 @@ mod tests {
assert_eq!(db.list_devices().unwrap().len(), 1);
db.log_event("info", "test", "ok", &serde_json::json!({"a":1})).unwrap();
assert_eq!(db.list_events(10).unwrap().len(), 1);
{
let conn = db.lock().unwrap();
conn.execute(queries::INSERT_EVENT, rusqlite::params![(Utc::now() - Duration::days(40)).to_rfc3339(), "info", "old", "old", "{}"] ).unwrap();
}
assert_eq!(db.prune_events(30).unwrap(), 1);
assert_eq!(db.list_events(10).unwrap().len(), 1);
let access_token = ApiTokenInfo {
id: "token-1".into(),