Repository navigation
Drop parameter_values.dynamic_id, its single-owner check and its per-dynamic index - #4351
Merged
Merged
Conversation
Revision 1c651058fac5 is to drop parameter_values.dynamic_id with its key to dynamics, ck_parameter_values_single_owner and the per-dynamic partial unique index, and to replace the current-law index, whose condition named the column, with uq_parameter_values_current_law_parameter_start_date on policy_id IS NULL. - A Postgres test of the revision: the schema change and its exact downgrade against the parent built from the base, surviving rows and the new index, a downgrade through 7f7335f0eb31 and back, what a row still naming a dynamic becomes, and the deploy's privilege steps. - The revision chain, the generated operations, the model's columns, checks and indexes, the lifecycle head check and CI's lifecycle script. - Tests that stored or read a dynamic's value in parameter_values at the head drop it; tests of earlier revisions use ParameterValueWithDynamic, a column-only class of the table as those revisions leave it. - The dynamics revisions' unit tests move, unchanged, from test_alembic_v2_revisions to test_alembic_v2_dynamic_revisions, which keeps the first under the 1,500-line limit for test code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Revision 1c651058fac5, on 7f7335f0eb31, autogenerated with no corrections after ParameterValue lost dynamic_id, ck_parameter_values_single_owner and uq_parameter_values_dynamic_parameter_start_date. 7f7335f0eb31 moved every dynamic's values to dynamic_parameter_values, so a parameter_values row is now a policy's value or a current-law value. PostgreSQL drops an index whose condition names a dropped column, and Alembic compares an index's condition by name only, so the current-law index is renamed uq_parameter_values_current_law_parameter_start_date, on policy_id IS NULL (the user's decision 2). The downgrade restores the column, its key, the check and both indexes, which 7f7335f0eb31's downgrade needs to copy dynamics' values back. - Current-law reads, publication's comparison and uniqueness check, pruning and publication's insert no longer name dynamic_id; a policy's values are inserted without it. - V2_ALEMBIC_HEAD_REVISION, CI's lifecycle script, the alembic-migrations skill (a section with the deploy order and the operator's read-only count, the user's decisions 1 and 3), the Stage 9 guide and the testing skill follow. - No role's privilege names the column. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review round 1 found no bug. Its one code-quality finding: once parameter_values lost dynamic_id, no test stored a dynamic's value where pruning could delete it, so nothing noticed if pruning stopped keeping dynamic_parameter_values rows with a dynamic_id. The pruning test of the dynamic-parameter publication module now stores a US dynamic on the old version, with a value of one of its model assumptions from the date its current-law value starts, and checks it is still there after pruning. With pruning's dynamic_id IS NULL filter removed, the test fails. The pruning module's docstring names where this is checked. 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 #4351 +/- ##
==========================================
- Coverage 93.90% 93.87% -0.03%
==========================================
Files 432 432
Lines 24196 24194 -2
Branches 3752 3752
==========================================
- Hits 22721 22713 -8
- Misses 846 852 +6
Partials 629 629
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…arameter_values dynamic_id drop branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from
v2plan/c1-51-dynamic-parameter-routes
to
master
November 27, 2026 13:32
…ues dynamic_id drop branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
C1 · 50 (#4347) merged without leaving dynamic_id out of ParameterValue's mapper, so the skill section's deploy order names C1 · 51a, which the user added to do it in its own release before this revision runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 27, 2026
C1 · 51a (v2plan/c1-51a-stop-mapping-parameter-values-dynamic-id at 1d01f57, with master at f780eb6) leaves dynamic_id out of ParameterValue's mapper while the table keeps it. This branch drops the column, so every conflict resolves to its removal: - ParameterValue has no dynamic_id field and no __mapper_args__. - Tests of the check and the per-dynamic index at the head (test_dynamic_table_models, test_model_persistence, test_alembic_v2_dynamics, test_v2_dynamic_persistence) stay removed, with their imports. - The skill's C1 · 50 section names revision 1c651058fac5 and C1 · 51a's release; "Columns a mapper leaves out" says dynamic_id was left out until that revision. Also undone, as they hold only while the table keeps the column: DIRECT_SQLALCHEMY_EXCEPTIONS' "columns_left_out_of_the_mapper", the role privilege test's wording, and test_models::test_parameter_values_keep_dynamic_id_which_the_model_no_longer_maps. C1 · 51a's statement tests, which check that no read, publication insert or policy insert names parameter_values.dynamic_id, stay. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk
changed the base branch from
master
to
v2plan/c1-51a-stop-mapping-parameter-values-dynamic-id
November 27, 2026 14:41
Base automatically changed from
v2plan/c1-51a-stop-mapping-parameter-values-dynamic-id
to
master
November 27, 2026 15:02
…rop branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_id drop branch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was previously 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 #4350
Summary
Revision
1c651058fac5, on7f7335f0eb31(#4347), drops what dynamics' values needed inparameter_values. Since7f7335f0eb31those values aredynamic_parameter_valuesrows, so aparameter_valuesrow is now a policy's value or a current-law value.Based on
master, where #4347 (C1 · 50), #4349 (C1 · 51) and #4353 (C1 · 51a, merged 2026-11-27 as3eb9637a6) have merged. #4353 leavesdynamic_idout ofParameterValue's mapper while the table keeps it; its branch was merged in here with each conflict resolved to the column's removal.The revision was autogenerated with
--rev-id 1c651058fac5, with no post-generation correction. It drops:parameter_values.dynamic_id, with its keyfk_parameter_values_dynamic_id_dynamics;ck_parameter_values_single_owner;uq_parameter_values_dynamic_parameter_start_date.The current-law index is renamed.
uq_parameter_values_canonical_parameter_start_datehad the conditionpolicy_id IS NULL AND dynamic_id IS NULL, and PostgreSQL drops an index whose condition names a dropped column. Alembic compares an index's condition by name only. So the model renames ituq_parameter_values_current_law_parameter_start_date, with the conditionpolicy_id IS NULL, and autogenerate replaces it.The downgrade adds the column back empty, with its key, the check and both old indexes. That way
7f7335f0eb31's downgrade can copy dynamics' values back intoparameter_valueswith theirdynamic_id.Code:
ParameterValueloses the field, the check and the per-dynamic index./v2/parameter-values,/v2/model-catalog/parameters), publication's comparison and uniqueness check, pruning, publication's insert, and the insert of a policy's values.V2_ALEMBIC_HEAD_REVISIONis1c651058fac5.Grants: no role's privilege names the column. Every grant on
parameter_valuesis on the whole table.Docs:
alembic-migrations.mdgains the section "API v2 parameter values without dynamics", and its pruning wording, the downgrade-chain paragraph and the dynamics sections are updated. The Stage 9 guide's pruning wording is updated too.Decisions (the user, 2026-11-26)
An earlier release stops mapping the column. The deploy upgrades the schema before the new release takes traffic, and a whole-row load names every mapped column, so the API v1 release that serves while this revision runs must leave
dynamic_idout ofParameterValue's mapper. Keep dynamic parameters and their values in their own tables #4347 was to do it, but merged without that change, so tracker task C1 · 51a does it in its own pull request and release, Stop mapping parameter_values.dynamic_id in API v1, keeping the column #4353 (decided 2026-11-27). Until it is in production,mastermaps the column.The current-law index is renamed in the generated order, rather than corrected by hand.
An operator counts first. A row that still has a
dynamic_idbecomes a current-law value when the column goes. That happens silently, unless it shares its parameter and start date with an existing current-law value; then the new index fails the upgrade and nothing changes. None is expected, but before merging, run this read-only count in staging and production. Both counts must be 0:Deploy order
A merge to
masterreleases this and runs the revision in staging and production in one release run. So it merges only after all of these hold, in both environments:3eb9637a6), which stops mappingParameterValue.dynamic_id, is in production. Keep dynamic parameters and their values in their own tables #4347 (C1 · 50, with revision7f7335f0eb31) and Serve dynamic parameters as their own v2 metadata category, US simulation.* included #4349 (C1 · 51) have merged; their release must be in production too.parameter_values.dynamic_id, so every policy read would fail once the column is gone.7f7335f0eb31.During the upgrade, the drop of the old index locks
parameter_valuesuntil the migration transaction commits. Building the new index reads every current-law value, millions of rows, so reads and writes of the table wait until the build finishes. API v1 and the simulation service time statements out after 5 seconds, so a longer wait fails them. For comparison,9d1d12a7ac58's index build, which read every row but indexed only dynamics' rows, took about 10 seconds in production. In production nothing reads these rows through the v2 routes yet. The dual-write v1-to-v2 policy copy writes them; a failed copy is logged, and the v1 response is unchanged.Simulation service
Tested from #1129's branch (
2db16a87) against a database at1c651058fac5, withSIMULATION_REQUIRE_PUBLIC_API_SCHEMA=1. 299 test cases pass, none skipped. They are #1129's changed tests and the six schema comparison tests that the weekly drift run againstmasteralso selects.The simulation service's
ParameterValuemaps nodynamic_id, and its comparison checks only the columns it reads. Its test helpers write nodynamic_id, and its readiness check grantsSELECTon the whole table. It needs nothing beyond #1129.Testing
3685235ef), then the change (57daf0884). Every changed test passes by node ID: 43 unit cases, 18 migration cases and 17 role-based cases.tests/integration/test_alembic_v2_parameter_values_dynamic_id_drop.pychecks:7f7335f0eb31and back;ParameterValueWithDynamic, a mapped class of the table as those revisions leave it.tests/unit/v2/test_alembic_v2_dynamic_revisions.py, which keepstest_alembic_v2_revisions.pyunder the 1,500-line limit.33e14c352: the dynamic-parameter pruning test now stores a dynamic's value and checks that pruning keeps it. It fails with pruning'sdynamic_id IS NULLfilter removed.alembic -c alembic-v2.ini checkfinds no difference.reconcile_v2_privileges.py apply --create-missing-rolesandverify,lint-imports,python -m scripts.rules validate,run_quality_guards.py, ruff, ruff format and mypy pass. mypy reports only the seven errorsmetadata.pyalready had, on lines this PR doesn't change.export_migration_contracts.pychanges nothing..github/scripts/test_alembic_v2_lifecycle.shnow runs the two new test modules. The only environment variables they read areV2_MIGRATION_DATABASE_URLandV2_ALEMBIC_DISPOSABLE_TEST. Both are literal values in thepostgres-lifecyclejob'senv:inalembic-v2-check.yml, whichpr.ymlandpush.ymlcall.DEPLOYMENT_ENVIRONMENTisn't set there, so the fixtures usetest. No secret is involved.Files that #4345, #4347 or #4349 also change
privileges.py..github/scripts/test_alembic_v2_lifecycle.sh,alembic-migrations.md,stage-9-v2-metadata.md;publication_inserts.py,publication_pruning.py,publication_reconciliation.py,migration_target.py,models/metadata.py,privileges.py;test_alembic_v2_dynamic_parameter_tables.py,test_v2_catalog_publication_dynamic_parameters.py,test_v2_catalog_publication_pruning.py,test_v2_dynamic_persistence.py,test_alembic_workflows.py,test_alembic_v2_revisions.py,test_metadata_service_pruned_versions.py.stage-9-v2-metadata.md,reads_parameters.py.C1 · 51a's change that stops mapping the column touches the same
dynamic_idlines. When this branch merges it, they resolve to their removal.🤖 Generated with Claude Code