Reputation: 2170
For a web-application (built using flask-appbuilder) I want to track all changes on the database when using SQLAlchemy declarative syntax on a PostgreSQL database. The flask-appbuilder "AuditMixin" already tracks the "last changed date" and "last changed user" to track who changed the row last. But I want to actually keep the old and new version of each row for accountability. I don't mind contributing something back to flask or flask-appbuilder or something because I don't think anything is available out of the box for that framework. So I wonder if any existing solution/paradigm/etc is out there for SQLAlchemy/PostgreSQL/databases in general (in that order preferably), before using my brain to come up with something myself (whatever smarter people did already is likely better than anything I come up with).
Upvotes: 6
Views: 1578
Reputation: 414
In addition to tracking created/modified date/user what you are already doing, use SQLAlchemy-Continuum
Continuum provides easy way for getting the changeset of given version object. Each version contains a changeset property which holds a dict of changed fields in that version.
https://sqlalchemy-continuum.readthedocs.io/en/latest/version_objects.html#changeset
Upvotes: 4