TDOE#174: Fix Student Program Dedupe, and add Program Status staging models. - #190
Merged
Conversation
…statuses models, edfi stage yaml doc for new program status models.
rlittle08
approved these changes
Jun 9, 2026
rlittle08
requested changes
Jun 9, 2026
6 tasks
rlittle08
approved these changes
Jun 9, 2026
rlittle08
force-pushed
the
feature/student_program_keys
branch
from
June 26, 2026 18:55
aa57edc to
0d6d53b
Compare
rlittle08
added a commit
that referenced
this pull request
Jul 23, 2026
…models. (#190) * move from pr-174: k_student_program, ed_org_id addition, new program statuses models, edfi stage yaml doc for new program status models. * add changelog, ed_org_id to base migrant edu model, fix small formatting * removed school year * added casting for designatedBy * k_student_program was missing from disabilities model --------- Co-authored-by: rlittle08 <rlittle@edanalytics.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description & motivation
This PR is a subset of TN's enhancements PR #174, pulled forward separately because this piece is ready to ship while the rest of that work is still being scoped.
It adds a
k_student_programsurrogate key to all 8 student program association staging tables and modifies the dedupe CTE on each to partition byk_student_program. This fixes a bug in how these models are deduped: they were previously deduplicating without the full PK, specifically missinged_org_id. This surfaces when a Program's ed org is defined at a different level than the Association's ed org and a student is associated with the same Program at two different ed orgs. For example, if a Program is defined at the District level but a student within that District is associated with it at two different Schools (say, they switched schools midyear), the current implementation dedupes those two Association rows down to one, even though they represent enrollment at two distinct Schools.Main highlights:
k_student_programsurrogate key added to all 8 parent student program association stage models, with dedupe updated to partition on it. Key components:tenant_code,api_year,student_unique_id,ed_org_id,program_ed_org_id,program_name,program_type,program_enroll_begin_date.ed_org_idandk_student_programadded to all existing program sub-table models, sinceed_org_idis part of the PK._program_participation_statusessub-tables, one per program association type, unpackingv_program_participation_statusesinto flat rows across all Student Program Association models (consistent with the existing pattern for Program Services sub-tables).Warning
This PR is a direct sibling of edu_wh's PR: edanalytics/edu_wh#249
They must be merged in unison.
PR Merge Priority:
Changes to existing files:
Parent program association stage models:
base_ef3__student_migrant_education_program_associations.sql: Addedv:programReference:educationOrganizationId::integer as program_ed_org_id. This field was never extracted for migrant education.Added
k_student_programviadbt_utils.generate_surrogate_keyand updateddbt_utils.deduplicateto partition by it, replacing the oldk_student, k_program, program_enroll_begin_date, school_yearpartition. The old partition omitteded_org_id, which is part of the Ed-Fi natural key for all student program associations.stg_ef3__student_program_associations.sql,stg_ef3__student_cte_program_associations.sqlstg_ef3__student_homeless_program_associations.sqlstg_ef3__student_language_instruction_program_associations.sqlstg_ef3__student_migrant_education_program_associations.sqlstg_ef3__student_school_food_service_program_association.sqlstg_ef3__student_special_education_program_associations.sqlstg_ef3__student_title_i_part_a_program_associations.sqlExisting program sub-table models:
k_student_programanded_org_idto each SELECT list.stg_ef3__stu_cte__program_services.sqlstg_ef3__stu_homeless__program_services.sqlstg_ef3__stu_lang_instr__program_services.sqlstg_ef3__stu_lang_instr__proficiency_assessments.sqlstg_ef3__stu_migrant_edu__program_services.sqlstg_ef3__stu_school_food_service__program_services.sqlstg_ef3__stu_spec_ed__program_services.sqlstg_ef3__stu_title_i_part_a__program_services.sqlstg_ef3__stu_title_i_part_a__services.sqlBug fixes caught in review:
stg_ef3__stu_program__program_participation_statuses.sql: Removedschool_yearfrom the SELECT. The genericstudent_program_associationsparent exposesapi_year as school_yearand an earlier draft included it, but none of the other 7_program_participation_statusessub-tables do (or sub-tables in this repo in general), so it was dropped for consistency.New files created:
All 8 new sub-tables follow the same pattern as the existing
_program_servicesmodels: theyref()the corresponding parent stage model, laterally flattenv_program_participation_statusesviajson_flatten, and selectk_student_program, the standard key columns (k_student,k_student_xyear,k_program,k_lea,k_school,ed_org_id), the enrollment dates, and the status fields (participation_status,status_begin_date,designated_by,status_end_date). The spec-ed variant adds anextendedCTE to callextract_extensionafter the flatten step, mirroring the same pattern instg_ef3__stu_spec_ed__program_services(necessary because the spec-ed array nests its ownv_ext, creating an ambiguity if extensions are applied before the flatten).stg_ef3__stu_cte__program_participation_statuses.sqlstg_ef3__stu_homeless__program_participation_statuses.sqlstg_ef3__stu_lang_instr__program_participation_statuses.sqlstg_ef3__stu_migrant_edu__program_participation_statuses.sqlstg_ef3__stu_program__program_participation_statuses.sqlstg_ef3__stu_school_food_service__program_participation_statuses.sqlstg_ef3__stu_spec_ed__program_participation_statuses.sqlstg_ef3__stu_title_i_part_a__program_participation_statuses.sqlTests and QC done:
dbt compilecleank_student_programconfirmed unique per parent model