From 73c5f31f9790553acb90f0e3936ad76e0f227312 Mon Sep 17 00:00:00 2001 From: david kiania Date: Fri, 19 Jun 2026 12:34:43 +0300 Subject: [PATCH] feat(reporting): fn_inc_filter_options for explorer dropdowns (migration 14) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Distinct engineers (owner, case-normalized), distinct clusters, and currently-open ticket ids — feeds the ticket-explorer pulldowns. Backs GET /webhook/inc-filter-options. Validated: 74 owners, 43 clusters, 489 open ids. Co-Authored-By: Claude Opus 4.8 --- migrations/14_inc_filter_options.sql | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 migrations/14_inc_filter_options.sql diff --git a/migrations/14_inc_filter_options.sql b/migrations/14_inc_filter_options.sql new file mode 100644 index 0000000..3bbbfc9 --- /dev/null +++ b/migrations/14_inc_filter_options.sql @@ -0,0 +1,39 @@ +-- 14_inc_filter_options.sql — fleettickets · ticket-explorer dropdown options +-- ───────────────────────────────────────────────────────────────────────────── +-- reporting.fn_inc_filter_options feeds the FleetOps ticket-explorer pulldowns: +-- distinct engineers (owner, case-normalized like migration 12/13), distinct +-- clusters, and the currently-open ticket ids (closed ids are ~22k → too many for a +-- pulldown; use the explorer's ticket-id substring search for historical lookups). +-- Backs GET /webhook/inc-filter-options. Idempotent (CREATE OR REPLACE). +-- ───────────────────────────────────────────────────────────────────────────── + +SET search_path = tickets, public; + +CREATE OR REPLACE FUNCTION reporting.fn_inc_filter_options() + RETURNS jsonb LANGUAGE sql STABLE AS $fn$ + SELECT jsonb_build_object( + 'owners', (SELECT COALESCE(jsonb_agg(o ORDER BY o), '[]'::jsonb) + FROM (SELECT DISTINCT initcap(lower(NULLIF(owner, ''))) AS o + FROM tickets.inc WHERE NULLIF(owner, '') IS NOT NULL) s), + 'clusters', (SELECT COALESCE(jsonb_agg(c ORDER BY c), '[]'::jsonb) + FROM (SELECT DISTINCT cluster AS c + FROM tickets.inc WHERE NULLIF(cluster, '') IS NOT NULL) s), + 'open_ticket_ids', (SELECT COALESCE(jsonb_agg(ticket_id ORDER BY ticket_id), '[]'::jsonb) + FROM tickets.inc WHERE COALESCE(is_actionable, false)) + ); +$fn$; + +COMMENT ON FUNCTION reporting.fn_inc_filter_options() IS + 'FleetOps ticket explorer dropdown options: distinct owners (normalized), clusters, ' + 'and open ticket ids. fleettickets 14.'; + +-- grants (guarded: roles may not exist on a fresh DB) +DO $grants$ +BEGIN + IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'dashboard_ro') THEN + GRANT EXECUTE ON FUNCTION reporting.fn_inc_filter_options() TO dashboard_ro; + END IF; + IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'grafana_ro') THEN + GRANT EXECUTE ON FUNCTION reporting.fn_inc_filter_options() TO grafana_ro; + END IF; +END $grants$;