Skip to content

Commit 16ae2c5

Browse files
authored
Merge pull request #7 from edanalytics/feature/users_improvements
Feature/users improvements
2 parents bcedeb7 + e733e75 commit 16ae2c5

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

models/oneroster_1_1/or1_1__int_users_staff.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ staff_orgs as (
6363
staff_orgs_agg as (
6464
select
6565
k_staff,
66-
listagg({{ gen_sourced_id('school') }}, ',') as orgs
66+
listagg(distinct {{ gen_sourced_id('school') }}, ',') as orgs
6767
from staff_orgs
6868
group by all
6969
),
@@ -90,6 +90,7 @@ formatted as (
9090
null::string as "password",
9191
{{ gen_natural_key('staff') }} as "metadata.edu.natural_key",
9292
staff_role.staff_classification as "metadata.edu.staff_classification",
93+
null::string as "metadata.edu.primary_school",
9394
dim_staff.tenant_code
9495
from dim_staff
9596
join user_ids
@@ -99,4 +100,4 @@ formatted as (
99100
left join staff_orgs_agg
100101
on dim_staff.k_staff = staff_orgs_agg.k_staff
101102
)
102-
select * from formatted
103+
select * from formatted

models/oneroster_1_1/or1_1__int_users_student.sql

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ student_orgs as (
4343
dim_school.k_lea,
4444
dim_school.k_school,
4545
dim_school.school_id,
46+
{{ gen_sourced_id('school') }} as sourced_id,
4647
student_school.tenant_code
4748
from student_school
4849
join dim_school
@@ -51,8 +52,10 @@ student_orgs as (
5152
student_orgs_agg as (
5253
select
5354
k_student,
54-
k_lea,
55-
listagg({{ gen_sourced_id('school') }}, ',') as orgs
55+
listagg(distinct sourced_id, ',') as orgs,
56+
-- create columns for primary school extension
57+
max_by(sourced_id, is_primary_school, 1)[0] as primary_school_sourced_id,
58+
max_by(sourced_id, entry_date, 1)[0] as latest_school_sourced_id
5659
from student_orgs
5760
group by all
5861
),
@@ -71,7 +74,7 @@ formatted as (
7174
true as "enabledUser",
7275
student_orgs_agg.orgs as "orgSourcedIds",
7376
'student' as "role",
74-
null::varchar as "username",
77+
student_email.email_address as "username",
7578
user_ids.ids as "userIds",
7679
dim_student.first_name as "givenName",
7780
dim_student.last_name as "familyName",
@@ -85,11 +88,11 @@ formatted as (
8588
null::string as "password",
8689
student_keys.natural_key as "metadata.edu.natural_key",
8790
null::string as "metadata.edu.staff_classfication",
91+
coalesce(student_orgs_agg.primary_school_sourced_id, student_orgs_agg.latest_school_sourced_id) as "metadata.edu.primary_school",
8892
dim_student.tenant_code
8993
from dim_student
9094
join student_keys
9195
on dim_student.k_student = student_keys.k_student
92-
-- note that this join expands the grain by district in certain cases
9396
left join student_orgs_agg
9497
on dim_student.k_student = student_orgs_agg.k_student
9598
left join user_ids
@@ -101,4 +104,4 @@ formatted as (
101104
left join grade_level_xwalk
102105
on dim_student.grade_level = grade_level_xwalk.edfi_grade_level
103106
)
104-
select * from formatted
107+
select * from formatted

0 commit comments

Comments
 (0)