I have a table "delivery" with a "status" column (yes, I still think in tables, not sure if this is a cause for concern...). I need to refactor it to track status history rather than just the current status. I would want to be able to query this data later to present history to the user.
I thought of something like splitting into tables "delivery" and "delivery_statuses", with timestamps as the delivery goes from status to status e.g. new -> in_progress -> delivered etc.
Then I thought this seems like a common-enough pattern. Is there any sqlalchemy magic should I be aware of for this type of scenario? Are hybrid attributes relevant? e.g. I can see that I'll want to easily query a delivery for its (current) status, and that could get messy. I have skimmed the hybrid attributes docs, but at the moment they're a bit Greek / new to me. However I do note that they have a section on
hybrid attributes with relationships.
On IRC, I was also recommended to check out
versioning, which seems to be an example rather than an integral part of sqlalchemy, and I'm not finding it any simpler to parse those docs.
Or is this a job for association proxy, which I'd always assumed was for simplifying many-to-many relationships, not a one-to-many like this. (
(In fact, this becomes a one-to-one relationship, once I limit "delivery_statuses" to the latest row.)
I appreciate any insight into the "best" way to build such a structure in sqlalchemy, and I'm happy to clarify my requirements more, feel free to ask me if anything is unclear.