feat: Region-datasets join table and simulation year#95
Closed
anth-volk wants to merge 2 commits intoapp-v2-migrationfrom
Closed
feat: Region-datasets join table and simulation year#95anth-volk wants to merge 2 commits intoapp-v2-migrationfrom
anth-volk wants to merge 2 commits intoapp-v2-migrationfrom
Conversation
Each region can now link to multiple datasets (one per year, 2024-2035) via a many-to-many join table, and simulations store their year directly. seed_regions.py is the sole source of truth for region-to-dataset wiring. - Add RegionDatasetLink model (composite PK: region_id + dataset_id) - Remove dataset_id FK from Region, add datasets list relationship - Add year column to Simulation model - Alembic migration with data migration from old FK to join table - Update analysis.py and simulations.py to resolve datasets from join table with optional year filtering - Update seed_regions.py to create RegionDatasetLink entries based on dataset filepath patterns (states/, districts/, CPS fallback) - Remove region update code from import_state_datasets.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test fixtures were still setting dataset_id on Region (removed column). Now they create RegionDatasetLink entries via the join table instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
|
Closing and reopening — GitHub has been stuck for 5+ minutes trying to determine merge status. |
8 tasks
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.
Fixes #94
Summary
regions.dataset_idFK withregion_datasetsmany-to-many join table so each region can link to multiple yearly datasets (2024–2035)yearcolumn tosimulationstable for direct queryabilityyearparameter to economy analysis and simulation request schemasseed_regions.pyas the sole source of truth for region→dataset wiring (matches datasets by filepath pattern:states/,districts/, CPS fallback)import_state_datasets.pyTest plan
alembic upgrade head— join table created, data migrated, FK dropped, year column addedseed_regions.py— regions created with dataset links via join tableSELECT r.code, d.name, d.year FROM region_datasets rd JOIN regions r ON r.id = rd.region_id JOIN datasets d ON d.id = rd.dataset_id WHERE r.code = 'state/al' ORDER BY d.year→ multiple rows (one per year)POST /analysis/economic-impactwithregion: "state/al", year: 2026→ uses correct yearly datasetyear→ uses latest available year🤖 Generated with Claude Code