From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001
From: Martial Simon <msimon_fr@hotmail.com>
Date: Mon, 15 Sep 2025 01:08:27 +0200
Subject: add: graphs et rushs

---
 graphs/sql/maas/req04_view.sql | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 graphs/sql/maas/req04_view.sql

(limited to 'graphs/sql/maas/req04_view.sql')

diff --git a/graphs/sql/maas/req04_view.sql b/graphs/sql/maas/req04_view.sql
new file mode 100644
index 0000000..bd00c7d
--- /dev/null
+++ b/graphs/sql/maas/req04_view.sql
@@ -0,0 +1,21 @@
+CREATE MATERIALIZED VIEW memorin.outdated_devices AS
+    SELECT
+        serial_number,
+        version_id,
+        released_at,
+        eol_timestamp,
+        (
+            SELECT COUNT(*) AS versions_behind
+            FROM memorin.device_versions AS vs
+            WHERE vs.released_at > v.released_at
+        ) AS versions_behind
+    FROM
+        memorin.devices AS d,
+        memorin.device_versions AS v
+    WHERE eol_timestamp IS NOT NULL
+    AND v.id = version_id
+    AND serial_number IN (
+        SELECT serial_number
+        FROM memorin.devices
+        WHERE deactivated_at IS NULL
+    );
-- 
cgit v1.2.3

