Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add function for config_item path #1174

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions views/005_component_views.sql
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@ CREATE OR REPLACE FUNCTION lookup_component_config_id_related_components (
RETURNS TABLE (id UUID) AS $$
BEGIN
RETURN QUERY
WITH config_id_paths AS (
WITH root AS (
SELECT config_items.path, config_items.id FROM config_items WHERE config_items.id IN (SELECT config_id FROM components WHERE components.id = $1::UUID)
),
config_id_paths AS (
SELECT config_items.id
FROM config_items
WHERE starts_with(path, (SELECT CONCAT(config_items.path, '.', config_items.id) FROM config_items WHERE config_items.id IN (SELECT config_id FROM components WHERE components.id = $1::UUID)))
WHERE starts_with(path, config_item_full_path(root.path, root.id))
)
SELECT components.id
FROM components
Expand Down
11 changes: 11 additions & 0 deletions views/006_config_views.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
-- Add cascade drops first to make sure all functions and views are always recreated
DROP VIEW IF EXISTS configs CASCADE;


CREATE OR REPLACE FUNCTION config_item_full_path(path TEXT, id UUID)
RETURNS TEXT AS $$
BEGIN
RETURN CASE
WHEN path IS NOT NULL AND path <> '' THEN path || '.' || id::TEXT
ELSE id
END;
END;
$$ LANGUAGE plpgsql;

DROP FUNCTION IF EXISTS related_changes_recursive CASCADE;

CREATE MATERIALIZED VIEW IF NOT EXISTS
Expand Down
Loading