tracksolid_timescale_grafan.../db_audit/checks/data_gaps.sql
David Kiania 20d3ddb841 feat: add db_audit health checks, runner, and scheduled Forgejo workflow
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 21:40:29 +03:00

19 lines
618 B
SQL

-- Data gaps: enabled devices with no position_history or trips in last 7 days
SELECT
d.imei,
d.device_name,
d.enabled_flag,
MAX(ph.gps_time) AS last_position,
MAX(t.start_time) AS last_trip
FROM tracksolid.devices d
LEFT JOIN tracksolid.position_history ph
ON ph.imei = d.imei
AND ph.gps_time > NOW() - INTERVAL '7 days'
LEFT JOIN tracksolid.trips t
ON t.imei = d.imei
AND t.start_time > NOW() - INTERVAL '7 days'
WHERE d.enabled_flag = 1
GROUP BY d.imei, d.device_name, d.enabled_flag
HAVING MAX(ph.gps_time) IS NULL
AND MAX(t.start_time) IS NULL
ORDER BY d.imei;