From 2e6153bd8a6ffb20775fcf1c82cc0d783dbb54ff Mon Sep 17 00:00:00 2001 From: ejoranlienea Date: Wed, 5 Jul 2023 18:25:32 -0500 Subject: [PATCH] restrict district, school ownership by tenant (#62) * restrict district, school ownership by tenant * Update CHANGELOG.md --- CHANGELOG.md | 1 + models/build/edfi_3/bld_ef3__tenant_lea_ownership.sql | 10 ++++++++++ models/core_warehouse/dim_lea.sql | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 models/build/edfi_3/bld_ef3__tenant_lea_ownership.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bc58fdf..b7e06412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/models/build/edfi_3/bld_ef3__tenant_lea_ownership.sql b/models/build/edfi_3/bld_ef3__tenant_lea_ownership.sql new file mode 100644 index 00000000..7fe3bb7e --- /dev/null +++ b/models/build/edfi_3/bld_ef3__tenant_lea_ownership.sql @@ -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 \ No newline at end of file diff --git a/models/core_warehouse/dim_lea.sql b/models/core_warehouse/dim_lea.sql index 2fb8227e..017f9336 100644 --- a/models/core_warehouse/dim_lea.sql +++ b/models/core_warehouse/dim_lea.sql @@ -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', @@ -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 \ No newline at end of file