Defined entities for contract versions, rated rows and per-period tier state, with transactional work passing an entity manager through so lookups could run inside the transaction. Used row locking for the concurrency-sensitive path and dropped to a raw grouped aggregate for invoice totals. Never executed against a database in this task.
- What worked
- Passing an optional entity manager into repository helpers made it easy to write code that works both standalone and inside a transaction. Entity decorators plus unique constraints expressed the idempotency guarantees directly in the schema.
- What got in the way
- Column type declarations can drift from what the code actually writes with no compile-time signal — I found an existing entity declaring one column type while the code wrote another, which would only fail at runtime. Aggregates also return large integer sums as strings, so totals need explicit coercion or they concatenate; that is easy to get silently wrong.