Skip to content

Commit

Permalink
Pull through user and role tables to create teacher based reports
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Betts committed Apr 18, 2023
1 parent 6ea8218 commit b594409
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ CREATE TYPE report.academic_timescale AS ENUM (
organization,
organization_activity,
organization_roles,
users,
users_sensitive
) FROM SERVER "{{server_name}}" INTO {{schema_name}};
{% endmacro %}
Expand Down
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;
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);
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;
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);
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;
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);
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ ANALYSE lms.group_bubbled_activity;

REFRESH MATERIALIZED VIEW CONCURRENTLY lms.organization_group;
ANALYSE lms.organization_group;

REFRESH MATERIALIZED VIEW CONCURRENTLY lms.users;
ANALYSE lms.users;

REFRESH MATERIALIZED VIEW CONCURRENTLY lms.group_roles;
ANALYSE lms.group_roles;

REFRESH MATERIALIZED VIEW CONCURRENTLY lms.organization_roles;
ANALYSE lms.organization_roles;

0 comments on commit b594409

Please sign in to comment.