Skip to content

Commit

Permalink
restrict district, school ownership by tenant (#62)
Browse files Browse the repository at this point in the history
* restrict district, school ownership by tenant

* Update CHANGELOG.md
  • Loading branch information
ejoranlienea authored Jul 5, 2023
1 parent f0e3f60 commit 2e6153b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Allow assessment results to come through even if they don't match a xwalk entry
- Add `k_school` to more models
- Add configuration to customize the preferred email address for staff
- Restrict the relationships between tenant and LEAs/schools
## Fixes


Expand Down
10 changes: 10 additions & 0 deletions models/build/edfi_3/bld_ef3__tenant_lea_ownership.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- in multi-tenant systems, it is possible for each tenant to individually
-- define all the districts/schools in a state. We want to avoid having
-- each tenant individually define each district and school, and only
-- keep the definition from the tenant that actually has ownership
-- since the relationship between tenant and district is not codified anywhere,
-- we observe it from student enrollments.
select distinct ssa.tenant_code, lea_id
from {{ ref('stg_ef3__student_school_associations') }} ssa
join {{ ref('stg_ef3__schools') }} sch
on ssa.k_school = sch.k_school
7 changes: 6 additions & 1 deletion models/core_warehouse/dim_lea.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
with stg_lea as (
select * from {{ ref('stg_ef3__local_education_agencies') }}
),

tenant_lea_ownership as (
select * from {{ ref('bld_ef3__tenant_lea_ownership') }}
),
choose_address as (
{{ row_pluck(ref('stg_ef3__local_education_agencies__addresses'),
key='k_lea',
Expand Down Expand Up @@ -46,6 +48,9 @@ formatted as (
from stg_lea
left join choose_address
on stg_lea.k_lea = choose_address.k_lea
join tenant_lea_ownership
on stg_lea.tenant_code = tenant_lea_ownership.tenant_code
and stg_lea.lea_id = tenant_lea_ownership.lea_id
)
select * from formatted
order by tenant_code, k_lea

0 comments on commit 2e6153b

Please sign in to comment.