-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull through user and role tables to create teacher based reports
- Loading branch information
Jon Betts
committed
Apr 18, 2023
1 parent
6ea8218
commit e93410f
Showing
8 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
report/data_tasks/report/create_from_scratch/04_lms/05_users/01_users/01_create_view.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
DROP MATERIALIZED VIEW IF EXISTS lms.users CASCADE; | ||
|
||
CREATE MATERIALIZED VIEW lms.users AS ( | ||
SELECT * | ||
FROM ( | ||
SELECT | ||
CONCAT('us-', id) AS id, | ||
display_name, | ||
email, | ||
username, | ||
is_teacher, | ||
registered_date | ||
FROM lms_us.users | ||
|
||
UNION ALL | ||
|
||
SELECT | ||
CONCAT('ca-', id) AS id, | ||
display_name, | ||
email, | ||
username, | ||
is_teacher, | ||
registered_date | ||
FROM lms_ca.users | ||
) AS data | ||
ORDER BY id | ||
|
||
) WITH NO DATA; |
8 changes: 8 additions & 0 deletions
8
report/data_tasks/report/create_from_scratch/04_lms/05_users/01_users/02_initial_fill.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
DROP INDEX IF EXISTS lms.users_id_idx; | ||
|
||
REFRESH MATERIALIZED VIEW lms.users; | ||
|
||
ANALYSE lms.users; | ||
|
||
-- A unique index is mandatory for concurrent updates used in the refresh | ||
CREATE UNIQUE INDEX users_id_idx ON lms.users (id); |
24 changes: 24 additions & 0 deletions
24
...t/data_tasks/report/create_from_scratch/04_lms/05_users/02_group_roles/01_create_view.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
DROP MATERIALIZED VIEW IF EXISTS lms.group_roles CASCADE; | ||
|
||
CREATE MATERIALIZED VIEW lms.group_roles AS ( | ||
SELECT | ||
group_id, | ||
user_id, | ||
role | ||
FROM ( | ||
SELECT | ||
CONCAT('us-', group_id) AS group_id, | ||
CONCAT('us-', user_id) AS user_id, | ||
role | ||
FROM lms_us.group_roles | ||
|
||
UNION ALL | ||
|
||
SELECT | ||
CONCAT('ca-', group_id) AS group_id, | ||
CONCAT('ca-', user_id) AS user_id, | ||
role | ||
FROM lms_ca.group_roles | ||
) AS data | ||
ORDER BY group_id, user_id | ||
) WITH NO DATA; |
8 changes: 8 additions & 0 deletions
8
.../data_tasks/report/create_from_scratch/04_lms/05_users/02_group_roles/02_initial_fill.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
DROP INDEX IF EXISTS lms.group_roles_group_id_user_id_role_idx; | ||
|
||
REFRESH MATERIALIZED VIEW lms.group_roles; | ||
|
||
ANALYSE lms.group_roles; | ||
|
||
-- A unique index is mandatory for concurrent updates used in the refresh | ||
CREATE UNIQUE INDEX group_roles_group_id_user_id_role_idx ON lms.group_roles (group_id, user_id, role); |
24 changes: 24 additions & 0 deletions
24
...tasks/report/create_from_scratch/04_lms/05_users/03_organization_roles/01_create_view.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
DROP MATERIALIZED VIEW IF EXISTS lms.organization_roles CASCADE; | ||
|
||
CREATE MATERIALIZED VIEW lms.organization_roles AS ( | ||
SELECT | ||
organization_id, | ||
user_id, | ||
role | ||
FROM ( | ||
SELECT | ||
CONCAT('us-', organization_id) AS organization_id, | ||
CONCAT('us-', user_id) AS user_id, | ||
role | ||
FROM lms_us.organization_roles | ||
|
||
UNION ALL | ||
|
||
SELECT | ||
CONCAT('ca-', organization_id) AS organization_id, | ||
CONCAT('ca-', user_id) AS user_id, | ||
role | ||
FROM lms_ca.organization_roles | ||
) AS data | ||
ORDER BY organization_id, user_id | ||
) WITH NO DATA; |
8 changes: 8 additions & 0 deletions
8
...asks/report/create_from_scratch/04_lms/05_users/03_organization_roles/02_initial_fill.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
DROP INDEX IF EXISTS lms.organization_roles_group_id_user_id_role_idx; | ||
|
||
REFRESH MATERIALIZED VIEW lms.organization_roles; | ||
|
||
ANALYSE lms.organization_roles; | ||
|
||
-- A unique index is mandatory for concurrent updates used in the refresh | ||
CREATE UNIQUE INDEX organization_roles_group_id_user_id_role_idx ON lms.organization_roles (organization_id, user_id, role); |
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