From f0c5d0129417e43a2a35a1277de74bfdc31dab9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Eggert=20Lundsteen=20Olsen?= Date: Fri, 2 Oct 2026 13:07:32 +0200 Subject: [PATCH] Review 1.3: the overview works before the agent has migrated to 0016 GetInstancesAsync now reads insight.ConfiguredInstances only when it exists, so a 1.3 web UI (e.g. upgraded first on its own server) still shows the overview against a repository a 1.2 agent has not migrated yet. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../InsightRepository.Read.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/SQLInsight.Repository/InsightRepository.Read.cs b/src/SQLInsight.Repository/InsightRepository.Read.cs index d3ba057..7d7326a 100644 --- a/src/SQLInsight.Repository/InsightRepository.Read.cs +++ b/src/SQLInsight.Repository/InsightRepository.Read.cs @@ -93,18 +93,24 @@ public sealed partial class InsightRepository public async Task> GetInstancesAsync(CancellationToken cancellationToken = default) { await using var connection = await OpenAsync(cancellationToken).ConfigureAwait(false); + // 1.3: paused or removed in Servere og databaser. A name without any configuration row (history from before 1.3) + // counts as monitored, as it did. Guarded, so a 1.3 web UI still shows the overview against a repository the + // agent has not migrated yet (e.g. the web upgraded first on its own server). var rows = await connection.QueryAsync(""" + DECLARE @configured TABLE (Name nvarchar(128) NOT NULL PRIMARY KEY, Configured int NOT NULL, Active int NOT NULL, Paused int NOT NULL); + IF OBJECT_ID(N'insight.ConfiguredInstances') IS NOT NULL + INSERT @configured (Name, Configured, Active, Paused) + SELECT Name, COUNT(*), MAX(CASE WHEN RemovedAt IS NULL THEN 1 ELSE 0 END), MAX(CASE WHEN RemovedAt IS NULL AND Paused = 1 THEN 1 ELSE 0 END) + FROM insight.ConfiguredInstances + GROUP BY Name; + SELECT i.InstanceId, i.Name, i.ServerName, i.ProductVersion, i.ProductLevel, i.ProductUpdateLevel, i.Edition, i.EngineEdition, i.ConnectionProvider, i.UsedLegacyFallback, i.LastSeenAt, i.LastErrorAt, i.LastError, ISNULL(f.Critical, 0) AS Critical, ISNULL(f.High, 0) AS High, ISNULL(f.Medium, 0) AS Medium, ISNULL(f.Low, 0) AS Low, ISNULL(f.Info, 0) AS Info, ISNULL(r.NotMeasurable, 0) AS NotMeasurable, ISNULL(r.ManualChecks, 0) AS ManualChecks, CAST(ISNULL(c.Paused, 0) AS bit) AS Paused, CAST(CASE WHEN c.Configured > 0 AND c.Active = 0 THEN 1 ELSE 0 END AS bit) AS Removed FROM insight.Instances i - /* 1.3: paused or removed in Servere og databaser. A name without any configuration row (history from before - 1.3) counts as monitored, as it did. */ - OUTER APPLY (SELECT COUNT(*) AS Configured, MAX(CASE WHEN RemovedAt IS NULL THEN 1 ELSE 0 END) AS Active, - MAX(CASE WHEN RemovedAt IS NULL AND Paused = 1 THEN 1 ELSE 0 END) AS Paused - FROM insight.ConfiguredInstances WHERE Name = i.Name) c + LEFT JOIN @configured c ON c.Name = i.Name OUTER APPLY (SELECT SUM(CASE WHEN Severity = 4 THEN 1 ELSE 0 END) AS Critical, SUM(CASE WHEN Severity = 3 THEN 1 ELSE 0 END) AS High, SUM(CASE WHEN Severity = 2 THEN 1 ELSE 0 END) AS Medium, SUM(CASE WHEN Severity = 1 THEN 1 ELSE 0 END) AS Low, SUM(CASE WHEN Severity = 0 THEN 1 ELSE 0 END) AS Info