Repository navigation
Conversation
`constituency_impacts` and `local_authority_impacts` stored each area's hex-map position in required `x` and `y` integer columns. Nothing reads or writes either table, and the app draws its maps from its own layout files, so the positions are unused. - `ConstituencyImpact` and `LocalAuthorityImpact` no longer define `x` and `y`. - v2 revision `e86f19a6c4da` was autogenerated from that metadata with `alembic -c alembic-v2.ini revision --autogenerate --rev-id e86f19a6c4da`, with no post-generation corrections. Its upgrade drops the four columns; its downgrade adds them back as required integers, which works only while both tables are empty. It is the new `V2_ALEMBIC_HEAD_REVISION`. - The previous Public API revision still maps these columns, but no managed database role holds any privilege on either table, so it can't read or write them during the deploy window or after a rollback. A new lifecycle test checks that the four columns are the only difference from the Stage 12A schema. The Stage 12A previous-revision test now upgrades to the Stage 12A revision, which it was written for, instead of head. - The Alembic guide documents the revision, and the Stage 12A guide names its own revision where it said head. Tests were written first and seen failing: the model test found `x` and `y` on both tables, the revision chain and revision-text tests found no `e86f19a6c4da`, and the lifecycle tests found the columns still present at head. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4103 +/- ##
===========================================
+ Coverage 50.82% 87.83% +37.01%
===========================================
Files 254 270 +16
Lines 14635 16054 +1419
Branches 2339 2626 +287
===========================================
+ Hits 7438 14101 +6663
+ Misses 6570 1284 -5286
- Partials 627 669 +42 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch was successfully deployed
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 #4102
Warning
Deploying this PR changes the staging and production v2 database schemas. The release's v2 migration job drops four columns, and their values can't be recovered. Anthony must approve the merge, and it waits until after the UK Budget on 28 October 2026.
Summary
API v2's
constituency_impactsandlocal_authority_impactstables stored each area's hex-map position in requiredxandyinteger columns. Nothing reads or writes either table, and the app draws its maps from its own layout files, so the positions are unused.ConstituencyImpactandLocalAuthorityImpactno longer definexandy.e86f19a6c4da(parentfbb7488ebe8a) was autogenerated from that metadata withuv run alembic -c alembic-v2.ini revision --autogenerate --rev-id e86f19a6c4da, against a disposable Postgres database at the previous head. It has no post-generation corrections. Its upgrade drops the four columns; its downgrade adds them back as required integers without a server default, which works only while both tables are empty.V2_ALEMBIC_HEAD_REVISIONis nowe86f19a6c4da.policyengine_v2_runtime,policyengine_v2_catalog_writer,policyengine_stage12_<environment>) holds any privilege on them inpolicyengine_api/data/v2/privileges.py, and no Public API code refers to them outside the models.test_stage_12a_schema_serves_the_previous_revisionupgraded to head. It now upgrades tofbb7488ebe8a, the revision it was written for, because head now drops columns that its parent revision maps. A new lifecycle test,test_area_impact_coordinate_removal_changes_nothing_else, checks that the four columns are the only difference betweenfbb7488ebe8aand head.docs/engineering/skills/alembic-migrations.md) documents the revision, and the Stage 12A guide names its own revision where it said head.No route, request or response changes: nothing serves these tables. No CI workflow, Docker image or deployment code changes; the existing v2 seed workflow applies the revision before each Cloud Run deploy. No inline ruff suppressions are added.
Testing
The work was done red-green: the tests were written first and seen failing, then the code was written and both were committed together in
b03f88e55.Seen failing before the change (5 failed, 64 passed):
tests/unit/v2/test_models.py::test_uk_area_impacts_store_no_map_coordinates:xandywere on both tables.tests/unit/v2/test_alembic_v2.py::test_v2_revision_chain_has_generated_policy_and_user_identity_changes: the chain had no revision afterfbb7488ebe8a.tests/unit/v2/test_alembic_v2.py::test_area_impact_coordinate_removal_is_generated_and_reversible: the revision file didn't exist.tests/integration/test_alembic_v2_lifecycle.py::test_empty_upgrade_check_base_downgrade_and_reupgrade: head still had the columns.tests/integration/test_alembic_v2_lifecycle.py::test_area_impact_coordinate_removal_changes_nothing_else: no columns were dropped.After the change, against a disposable
postgres:17database namedpolicyengine_v2_alembic_test, set up as thealembic-v2-check.ymlservice container is:FLASK_DEBUG=1 uv run --frozen pytest tests/unit/v2/test_models.py tests/unit/v2/test_alembic_v2.py tests/integration/test_alembic_v2_lifecycle.py tests/unit/v2/test_catalog_publication.py tests/unit/v2/test_user_association_migration_qualification.py tests/unit/v2/test_privilege_manifest.py -q: 122 passed.tests/integration/test_v2_privilege_reconciliation.py(DEPLOYMENT_ENVIRONMENT=test): 3 passed.tests/unit/test_alembic_skill.py,tests/unit/test_alembic_workflows.py,tests/unit/data/test_database_access_boundaries.py: 26 passed.alembic -c alembic-v2.ini checkbefore generating: exactly fourremove_columnoperations, one for each column. After upgrading:No new upgrade operations detected.alembic -c alembic-v2.ini downgrade -1, thenupgrade head, thencurrent --check-heads:e86f19a6c4da (head).make format,ruff check .,uv run --frozen --extra dev mypy,python scripts/run_quality_guards.pyandpython scripts/export_migration_contracts.py(no generated changes): all pass.The full suite runs in CI.
🤖 Generated with Claude Code