From 30a9d45f5322a63c2adf1de7a248ba3a9a0c3903 Mon Sep 17 00:00:00 2001
From: Dan Goodliffe <dan@randomdan.homeip.net>
Date: Sat, 20 Dec 2025 15:16:25 +0000
Subject: Add job for puring old access log entries from the database

---
 src/sql/accessLogPurgeOld.sql | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 src/sql/accessLogPurgeOld.sql

(limited to 'src/sql/accessLogPurgeOld.sql')

diff --git a/src/sql/accessLogPurgeOld.sql b/src/sql/accessLogPurgeOld.sql
new file mode 100644
index 0000000..8379018
--- /dev/null
+++ b/src/sql/accessLogPurgeOld.sql
@@ -0,0 +1,11 @@
+WITH scope AS (
+	SELECT id
+	FROM access_log
+	ORDER BY id
+	LIMIT ?
+), scoperange AS (
+	SELECT min(id) minid, max(id) maxid
+	FROM scope)
+DELETE FROM access_log USING scoperange
+WHERE request_time < CURRENT_DATE - ?::interval
+	AND access_log.id BETWEEN scoperange.minid AND scoperange.maxid
-- 
cgit v1.2.3

