Skip to content

Commit

Permalink
feat: add name/type to changes api
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Mar 15, 2024
1 parent 92908b9 commit fa637a5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions views/006_config_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,36 @@ BEGIN
SELECT * from related_configs_recursive(config_id, type_filter, include_deleted_configs, 1);
END;
$$ LANGUAGE plpgsql;

-- related config changes recursively
DROP FUNCTION IF EXISTS related_changes_recursive(UUID, TEXT, BOOLEAN);

CREATE FUNCTION related_changes_recursive (
lookup_id UUID,
type_filter TEXT DEFAULT 'downstream', -- 'downstream', 'upstream', or 'all'
include_deleted_configs BOOLEAN DEFAULT FALSE,
max_depth INTEGER DEFAULT 5
) RETURNS TABLE (
id uuid,
config_id uuid,
name TEXT,
type TEXT,
external_created_by TEXT,
created_at TIMESTAMP WITH TIME ZONE,
severity TEXT,
change_type TEXT,
source TEXT,
summary TEXT,
created_by uuid,
agent_id uuid
) AS $$
BEGIN
RETURN query
SELECT cc.id, cc.config_id, c.name, c.type, cc.external_created_by, cc.created_at, cc.severity, cc.change_type, cc.source, cc.summary,cc.created_by,c.agent_id
FROM config_changes cc
LEFT JOIN config_items c on c.id = cc.config_id
WHERE cc.config_id = lookup_id
OR cc.config_id IN (SELECT related_config_ids_recursive.id FROM related_config_ids_recursive(lookup_id, $2, $4))
;
END;
$$ LANGUAGE plpgsql;

0 comments on commit fa637a5

Please sign in to comment.