From a831542167265dd5d2fa984884f28a6b234848f9 Mon Sep 17 00:00:00 2001 From: Michal Fiedorowicz Date: Tue, 31 Dec 2024 22:18:51 +0000 Subject: [PATCH] fix: pg query for ingestion logs with latest change set only Signed-off-by: Michal Fiedorowicz --- diode-server/dbstore/postgres/migrations/00002_change_sets.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diode-server/dbstore/postgres/migrations/00002_change_sets.sql b/diode-server/dbstore/postgres/migrations/00002_change_sets.sql index 1fe7766b..bc9f9c6e 100644 --- a/diode-server/dbstore/postgres/migrations/00002_change_sets.sql +++ b/diode-server/dbstore/postgres/migrations/00002_change_sets.sql @@ -45,7 +45,7 @@ ALTER TABLE changes -- Create a view to join ingestion_logs with aggregated change_set and changes CREATE VIEW v_ingestion_logs_with_change_set AS -SELECT ingestion_logs.*, +SELECT DISTINCT ON (ingestion_logs.id) ingestion_logs.*, row_to_json(change_sets.*) AS change_set, JSON_AGG(changes.* ORDER BY changes.sequence_number ASC) FILTER ( WHERE changes.id IS NOT NULL ) AS changes FROM ingestion_logs