I'm starting to use SQLAlchemy for a new project where I was planning to implement an audit trail similar to the one proposed on these questions:
As I will have the full history of the "interesting" objects, I was thinking in allowing users to rollback to a given version, giving them the possibility to have unlimited undo
.
Would this be possible to be done in a clean way with SQLAlchemy?
What would be the correct way to expose this feature in the internal API (business logic and ORM)?
I was something along the ways of user.rollback(ver=42)
.
Although I haven't used SQLAlchemy specifically, I can give you some general tips that can be easily implemented in any ORM:
Document
and DocumentVersion
. Document
stores information that will never change between versions, and DocumentVersion
stores information that does change.DocumentVersion
a "parent" reference. Make a foreign key to the same table, pointing to the previous version of the document.Document
to the "current" version. Don't delete versions from the bottom of the chain.Example, create A, B, C, rollback to B, create D, E:
(A)
|
(B)
| \
(C) (D)
|
(E)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With