Skip to content

Declare uq_report_runs_id_report on sim's model of report_runs, with the API v1 pin on D1 · 0a's merge - #1179

Merged
anth-volk merged 4 commits into
mainfrom
v2plan/d1-0b-report-runs-id-report
Dec 2, 2026
Merged

anth-volk merged 4 commits into
mainfrom
v2plan/d1-0b-report-runs-id-report

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

Fixes #1178

Sim's mapped class of report_runs declares the unique constraint uq_report_runs_id_report on (id, report_id), which API v1's revision 7dcd2cd14330 adds (PolicyEngine/policyengine-api#4386, D1 · 0a), and public-api-commit moves to 41fc0151, API v1's merge of #4386.

Same-Repository Draft PR Check

  • This PR is a draft.
  • This PR is from a branch in PolicyEngine/policyengine-sim-api, not a personal fork.

Changelog

  • This PR adds a changelog fragment, changelog.d/<name>.<type>.md, whose type is breaking, added, changed, fixed or removed.

Summary

  • Why: #4386 adds a foreign key from user_report_associations (current_report_run_id, report_id) to report_runs (id, report_id), so a saved report's current run is one of its own report's runs. PostgreSQL requires a unique constraint on the referenced columns, so the revision adds uq_report_runs_id_report. test_the_models_match_the_public_api_tables compares sim's models with API v1's tables constraint by constraint (rule sim.persistence.models-match-public-api), so from #4386's merge on it fails against API v1's master, and the weekly drift run (public-api-schema-drift.yml) would fail.
  • ReportRun.__table_args__ declares UniqueConstraint("id", "report_id", name="uq_report_runs_id_report"), with the same name, columns and column order as API v1's revision and API v1's own ReportRun model.
  • libs/policyengine-simulation-persistence/public-api-commit moves from e0c9d2f7 to 41fc0151, API v1's merge commit of #4386, which is on API v1's master. Between the two, API v1 adds one other revision, 50430a2da57f (published_report_images), a table sim doesn't model, granted only to API v1's own runtime role.
  • The comment on uq_budget_window_runs_id_report now also names API v1's key from a saved report to its current budget window run, which #4386 adds.
  • Changelog fragment: changelog.d/d1-0b-report-runs-id-report.changed.md.
  • No behaviour change: sim never creates tables, and id is already the primary key, so the constraint refuses no row the service writes. No ON CONFLICT target, find-or-create path or constraint-name mapping in sim uses the set of unique constraints on report_runs. user_report_associations isn't in sim's metadata. A merge to main releases and deploys the service and publishes policyengine-api-simulation-client, as every sim merge does.

Testing

Test first, with the existing comparison as the test: 45ce43a8 moves the pin alone, and the comparison fails; 5547a80b adds the constraint, and it passes. Only libs/policyengine-simulation-persistence/tests/test_public_api_schema.py::test_the_models_match_the_public_api_tables ran, selected by node ID, against a disposable PostgreSQL 17 database built with .github/scripts/public-api-schema-reference.sh at #4386's head e36efee7 (revision 7dcd2cd14330 applied):

Commit Result
45ce43a8 (pin moved, no constraint) fails on its assertion, with one difference: report_runs: the model has no constraint uq_report_runs_id_report (UNIQUE (id, report_id))
5547a80b (constraint added) passes

#4386 then merged as 41fc0151, a merge commit whose tree is identical to e36efee7's, so a0981568 pins 41fc0151 without another run.

Sim's checks pass: the pinned Ruff format and lint, the rules registry render, the quality guards including file length, the lock checks, and Pyright for libs/policyengine-simulation-persistence.

Review

One round, which found no bugs: it confirmed the constraint matches API v1's, the pin is on API v1's master with the tested tree, nothing else API v1 changed between the two pins is compared, and no runtime path changes. Its code-quality note, that the comment on uq_budget_window_runs_id_report names only one of its two users, is fixed in 5ac9f2cc (comment only). No bugs are left.

What the merge waits for

It builds on main, not on another task's branch.

🤖 Generated with Claude Code

anth-volk and others added 4 commits December 2, 2026 18:26
…rison fails)

PolicyEngine/policyengine-api#4386's revision 7dcd2cd14330 adds the unique
constraint uq_report_runs_id_report on report_runs (id, report_id), the
target of the saved reports' key to their current run. ReportRun doesn't
declare it yet, so the comparison with API v1's tables at this commit fails
on the missing constraint. The pin names #4386's head until it merges, as
the library's README says; it moves to the merge commit before this merges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
API v1's revision 7dcd2cd14330 (PolicyEngine/policyengine-api#4386) adds
the unique constraint on report_runs (id, report_id) that a saved report's
key to its current run refers to. ReportRun declares it, so the models
match API v1's tables again. id is already the primary key, so the
constraint refuses no row the service writes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#4386 merged as 41fc0151 with a merge commit, whose tree is the same as
its head e36efee7, which the comparison ran against; the pin now names a
commit on API v1's master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s users

Review round 1's code-quality note: API v1's revision 7dcd2cd14330 also
makes the constraint the target of a saved report's key to its current
budget window run. Comment only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk marked this pull request as ready for review December 2, 2026 17:29
@anth-volk
anth-volk merged commit 9c418bd into main Dec 2, 2026
28 checks passed
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.

Sim's model of report_runs lacks uq_report_runs_id_report, which API v1 adds

1 participant