From a45f829a7f88403dc170c5be3aad7a47eb16a3cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Cant=C3=B9?= Date: Fri, 14 Jun 2024 10:24:17 +0200 Subject: [PATCH] handle realtaed loggers --- .../20240508145818_related_loggers.sql | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 db/migrations/20240508145818_related_loggers.sql diff --git a/db/migrations/20240508145818_related_loggers.sql b/db/migrations/20240508145818_related_loggers.sql new file mode 100644 index 0000000..ebd9db2 --- /dev/null +++ b/db/migrations/20240508145818_related_loggers.sql @@ -0,0 +1,45 @@ +-- migrate:up +DROP VIEW flat_logger_files; + +CREATE VIEW flat_logger_files AS ( + WITH has_logger_type AS ( + SELECT + r.id, + array_agg(DISTINCT l."type") AS types, + li.deployment + FROM + ring AS r + JOIN logger_instrumentation AS li ON li.ring = r.id + JOIN logger AS l ON li.logger = l.id + GROUP BY + r.id, + li.deployment + ) + SELECT + li.id, + li.logger, + h.types AS related_logger_types, + li.ring, + li.status, + li.sampling_freq_s, + li.mass_g, + li.attachment_method, + li.mount_method, + li.startup, + li.deployment, + li.retrieval, + li.filename, + li.data_stored_externally, + li.comment, + l.type, + l.model + FROM + logger_instrumentation li + JOIN has_logger_type h ON h.id = li.ring + AND h.deployment = li.deployment + JOIN logger l ON li.logger = l.id +); + +GRANT SELECT ON public.flat_logger_files TO readonly; + +-- migrate:down