Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Mar 15, 2024
1 parent fe6e4bf commit 86f63c6
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions views/006_config_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -416,35 +416,40 @@ CREATE OR REPLACE FUNCTION related_config_ids_recursive (
config_id UUID,
type_filter TEXT DEFAULT 'outgoing',
max_depth INT DEFAULT 5
) RETURNS TABLE (id UUID,related_id UUID,relation_type TEXT,direction TEXT, depth INT) AS $$
BEGIN

IF type_filter = 'outgoing' THEN
RETURN query
) RETURNS TABLE (
id UUID,
related_id UUID,
relation_type TEXT,
direction TEXT,
depth INT
) AS $$
BEGIN
IF type_filter = 'outgoing' THEN
RETURN query
WITH RECURSIVE cte (config_id, related_id, relation, depth) AS (
SELECT parent.related_id, parent.config_id as related_id, parent.relation, 1::int
FROM config_relationships parent
WHERE parent.config_id = related_config_ids_recursive.config_id
AND deleted_at IS NULL
UNION ALL
UNION ALL
SELECT
child.related_id, parent.config_id as related_id, child.relation, parent.depth +1
FROM config_relationships child, cte parent
WHERE child.config_id = parent.config_id
AND parent.depth <= max_depth
AND deleted_at IS NULL
) CYCLE config_id SET is_cycle USING path
SELECT DISTINCT cte.config_id,cte.related_id, cte.relation,type_filter,cte.depth
SELECT DISTINCT cte.config_id, cte.related_id, cte.relation, type_filter, cte.depth
FROM cte
ORDER BY cte.depth asc;
ELSEIF type_filter = 'incoming' THEN
RETURN query
ELSIF type_filter = 'incoming' THEN
RETURN query
WITH RECURSIVE cte (config_id,related_id, relation,depth) AS (
SELECT parent.config_id, parent.related_id as related_id, parent.relation, 1::int
FROM config_relationships parent
WHERE parent.related_id = related_config_ids_recursive.config_id
AND deleted_at IS NULL
UNION ALL
UNION ALL
SELECT
child.config_id, child.related_id as related_id, child.relation, parent.depth +1
FROM config_relationships child, cte parent
Expand All @@ -455,13 +460,13 @@ IF type_filter = 'outgoing' THEN
SELECT DISTINCT cte.config_id, cte.related_id, cte.relation,type_filter,cte.depth
FROM cte
ORDER BY cte.depth asc;
ELSE
RETURN query
SELECT * FROM related_config_ids_recursive(config_id, 'incoming', max_depth)
UNION
SELECT * FROM related_config_ids_recursive(config_id, 'outgoing', max_depth);
END IF;
END;
ELSE
RETURN query
SELECT * FROM related_config_ids_recursive(config_id, 'incoming', max_depth)
UNION
SELECT * FROM related_config_ids_recursive(config_id, 'outgoing', max_depth);
END IF;
END
$$ LANGUAGE plpgsql;

-- related configs recursively
Expand Down

0 comments on commit 86f63c6

Please sign in to comment.