允许用户使用 SQLAlchemy 从数据库审计跟踪回滚
我开始将 SQLAlchemy 用于一个新项目,我计划在该项目中实施类似于针对以下问题提出的审计跟踪:
- 在 C# 中实现对象的审计跟踪?
- 审核跟踪和实施 SOX/HIPAA/etc,敏感数据的最佳实践
- 用于捕获审计跟踪的数据库设计想法
- DB Audit Trail 的最佳实现是什么?
- 这是创建审计跟踪的最佳方法吗?
- 为数据库应用程序留下审计跟踪/更改历史记录的有效策略?
- NHibernate 和 SqlServer 中的数据审核。
由于我将拥有“有趣”对象的完整历史记录,因此我正在考虑允许用户回滚到给定版本,从而使他们能够无限制地撤消。
使用 SQLAlchemy 可以以干净的方式完成此操作吗?
在内部 API(业务逻辑和 ORM)中公开此功能的正确方法是什么?
我是在 user.rollback(ver=42)
的道路上走来的。
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:
- Implementing Audit Trail for Objects in C#?
- Audit trails and implementing SOX/HIPAA/etc, best practices for sensitive data
- Ideas on database design for capturing audit trails
- What is the best implementation for DB Audit Trail?
- Is this the best approach to creating an audit trail?
- Effective strategy for leaving an audit trail/change history for DB applications?
- Data Auditing in NHibernate and SqlServer.
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)
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我没有专门使用过 SQLAlchemy,但我可以为您提供一些可以在任何 ORM 中轻松实现的一般提示:
Document
和DocumentVersion.
Document
存储在版本之间永远不会更改的信息,而DocumentVersion
存储会更改的信息。DocumentVersion
提供一个“父”引用。为同一个表创建一个外键,指向文档的先前版本。例如,创建A、B、C,回滚到B,创建D、E:
Although I haven't used SQLAlchemy specifically, I can give you some general tips that can be easily implemented in any ORM:
Document
andDocumentVersion
.Document
stores information that will never change between versions, andDocumentVersion
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: