Repository navigation
Description
What
Move every module that reads or writes database rows from SQLAlchemy Core to the SQLAlchemy ORM, so the rule sim.persistence.orm-only can go from ratcheted to enforced.
The rule says that code declares tables only as typed ORM mapped classes (DeclarativeBase, Mapped[...], mapped_column) and runs every statement through an ORM Session against those classes, never through Core Table objects or Connections. It lands ratcheted in #1090, with rules/baselines/orm-only.txt listing the 880 findings in today's code. A new finding fails CI, and each conversion removes its entries.
Plan
- Table models and sessions: both persistence libraries'
Table(...)declarations become mapped classes on one declarative base per library, andengine.pyhands out asessionmaker. Temporary aliases (household_jobs = HouseholdJob.__table__) keep the Core stores working, and the comparison with the Public API's schema keeps passing. - Service side, households: the household job and household report records and stores, and the Entrypoint's household services.
- Service side, economy and budget windows: reads, inputs, find-or-create, re-runs, shared rows and result models in
policyengine-simulation-persistence. - Modal side: every store in
policyengine-stage12-persistence, and the executor'sstage12_runtime/database_retry.py. - Connections, readiness and finish:
access.pyand the Entrypoint'ssimulation_database.py; remove the aliases, empty the baseline, set the rule toenforcedand remove its[rule.downgrade]section. Also drop thesqlmodeldependency thatpolicyengine-fastapikeeps after Answer 500 when a household job's commit is unconfirmed, and move sim's database code to the SQLAlchemy ORM #1090 deletes its unuseddatabase.py.
Steps 2 to 4 depend only on step 1, so they can run in parallel. Step 5 closes this issue.
This conversion comes before the cliff work: #1096 and #1099 are rebased onto it and their database code is redone on mapped classes and Sessions.
Activity
Require the SQLAlchemy ORM for database code, ratcheted