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

Pull through user and role tables to create teacher based reports #202

Merged
merged 1 commit into from
Apr 18, 2023
Merged
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
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;