Last active
January 23, 2023 10:08
-
-
Save pajachiet/ccdddd1ec2d06ebb9060ee4d8d17a9c2 to your computer and use it in GitHub Desktop.
This allows to create the base table for a dashboard with a sankey diagram visualizing relationships between role, table and dashboards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE VIEW table_to_role AS ( | |
SELECT | |
tables.id as table_id, | |
tables.table_name as table_name, | |
ab_role.name as role_name | |
FROM | |
tables | |
LEFT JOIN ab_view_menu ON ab_view_menu.name = tables.perm | |
LEFT JOIN ab_permission_view on ab_permission_view.view_menu_id = ab_view_menu.id | |
LEFT JOIN ab_permission on ab_permission_view.permission_id = ab_permission.id | |
LEFT JOIN ab_permission_view_role on ab_permission_view.id = ab_permission_view_role.permission_view_id | |
LEFT JOIN ab_role ON ab_role.id = ab_permission_view_role.role_id | |
WHERE | |
ab_permission.name = 'datasource_access' | |
AND tables.table_name is NOT NULL | |
); | |
CREATE OR REPLACE VIEW slice_role_table_dash AS ( | |
SELECT | |
slices.slice_name, | |
table_to_role.role_name, | |
table_to_role.table_name, | |
dashboards.dashboard_title | |
FROM | |
slices | |
INNER JOIN dashboard_slices ON slices.id = dashboard_slices.slice_id | |
INNER JOIN dashboards ON dashboards.id = dashboard_slices.dashboard_id | |
LEFT JOIN table_to_role ON slices.datasource_id = table_to_role.table_id | |
); | |
SELECT | |
role_name as source, | |
table_name as target, | |
slice_name, | |
role_name, | |
table_name, | |
dashboard_title | |
FROM slice_role_table_dash | |
UNION | |
SELECT | |
table_name as source, | |
dashboard_title as target, | |
slice_name, | |
role_name, | |
table_name, | |
dashboard_title | |
FROM slice_role_table_dash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment