Skip to content

Conversation

@anth-volk
Copy link
Contributor

@anth-volk anth-volk commented Feb 3, 2026

Fixes #74
Fixes #75
Fixes #76
Fixes #78


Warning

This PR is still under construction. Additional work may be needed before it's ready for review.

Important

The policyengine-app-v2 repo will also need changes to consume the modifications from this PR. Frontend work should be coordinated once this API is merged.

Important

Production database migration required. This PR switches from Supabase SQL migrations to Alembic. After merging, run alembic stamp a17ac554f4aa on the production database to mark existing schema as migrated. See .claude/skills/database-migrations.md for details.


Summary

This PR adds comprehensive household support to the API v2 alpha and migrates to Alembic for database migrations.

1. Stored Household CRUD (#74)

  • Household model with household_data JSONB storage
  • POST/GET/DELETE /households endpoints
  • Supports both UK and US household structures

2. User-Household Associations (#75)

  • UserHouseholdAssociation model linking users to households
  • POST/GET/PUT/DELETE /user-household-associations endpoints
  • Unique constraint on (user_id, household_id)

3. Household Impact Analysis (#76)

  • Extended Simulation model with SimulationType enum, household_id, household_result
  • Extended Report model with report_type field
  • POST/GET /analysis/household-impact endpoints
  • Supports single runs and baseline vs reform comparisons
  • Computes impact across all entity types (UK: person/benunit/household, US: person/tax_unit/spm_unit/family/marital_unit/household)

4. Alembic Migration System (#78)

  • Replaced SQLModel.metadata.create_all() with Alembic migrations
  • Initial migration creates all 21 tables with proper ordering
  • Auto-generates migrations from SQLModel model changes
  • Added comprehensive migration guidelines in .claude/skills/database-migrations.md
  • Archived old Supabase table migrations (storage migrations remain)

Database Migrations

Now managed by Alembic in alembic/versions/:

  1. d6e30d3b834d_initial_schema.py - Creates all 21 tables
  2. a17ac554f4aa_add_parameter_values_indexes.py - Adds performance indexes

Files Changed

New Files

  • src/policyengine_api/models/household.py
  • src/policyengine_api/models/user_household_association.py
  • src/policyengine_api/api/households.py
  • src/policyengine_api/api/user_household_associations.py
  • alembic/ - Alembic configuration and migrations
  • .claude/skills/database-migrations.md - Migration guidelines
  • scripts/seed_nevada.py - Nevada dataset seeding script
  • test_fixtures/fixtures_households.py
  • test_fixtures/fixtures_user_household_associations.py
  • test_fixtures/fixtures_analysis.py
  • tests/test_households.py
  • tests/test_user_household_associations.py
  • tests/test_analysis_household_impact.py

Modified Files

  • src/policyengine_api/models/simulation.py - Added SimulationType, household_id, household_result
  • src/policyengine_api/models/report.py - Added report_type
  • src/policyengine_api/models/__init__.py - Exports new models
  • src/policyengine_api/api/__init__.py - Registers new routers
  • src/policyengine_api/api/analysis.py - Added household-impact endpoints
  • src/policyengine_api/config/settings.py - Fixed database URL port
  • scripts/init.py - Now uses Alembic instead of create_all()
  • CLAUDE.md - Added Alembic documentation reference

Test Plan

  • Run unit tests for household CRUD
  • Run unit tests for user-household associations
  • Run unit tests for household impact analysis
  • Manual testing of endpoints
  • Verify Alembic migrations apply correctly locally
  • Run alembic stamp on production after merge

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

anth-volk and others added 7 commits February 3, 2026 00:55
- Replace synchronous inline calculation with async trigger pattern
- Add _trigger_household_impact() mirroring _trigger_economy_comparison()
- Add _run_local_household_impact() for local execution (blocking)
- Add _run_simulation_in_session() for running individual simulations
- Update POST endpoint to trigger and return immediately
- Add test script for manual end-to-end testing

Note: Local execution blocks the request (same as economic impact).
True async requires Modal functions (household_impact_uk/us).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Alembic for db migrations Add household impact analysis endpoints Add user-household associations Add stored household CRUD support

2 participants