Rybit
02-17-2010, 04:27 PM
So my team and I are working on a new project, and we need to keep an always-on audit trail. This is one of our first major projects using Rails for an internal business app.
This project uses Ruby on Rails as its framework with MySQL used with the ActiveRecord ORM datamapper for our development environment; our production environment will be ActiveRecord with Oracle, with transactions imported/synchronized to SAP via EAI conduit to BAPI/RFC invocation on an hourly interval.
We need to be able to audit models and its associated object changes. We require the ability to audit updates/deletions, recording a whodunit log for each revision, e.g, invoices, invoice lines; if I delete an invoice line in version 3, and add two invoice lines in version 4, and add one more invoice line in version 5, I'd like to be able to pull version 4 exactly as it was).
In short, an auditor must be able to look at a transaction and pull any previous revisions exactly how it looked from our software.
What is the best way to do this? My thinking is in the example of Invoices and InvoiceLines to create a new object called RevisedInvoices and RevisedInvoiceLines and have the database be triggered to copy the model when an update or deletion is called in SQL. On the other hand, I can control the logic better by programming the copy in a before_ hook in the app. Should I do this as a database trigger or should I let the MVC app logic handle the copying?
I know this isn't the most efficient way of building an audit trail since I am making entire copies rather than storing the delta changes for each revision. But since space is cheap, I'd like someone to give me their experience with building an audit trail, especially one with associations. If I change an invoice A with invoice lines B, C, and D, and I add another invoice line E, how can I audit/version associated objects? What do you guys think about cloning the model to a second a table such as a RevisedObject to do the trick?
Please advise.
This project uses Ruby on Rails as its framework with MySQL used with the ActiveRecord ORM datamapper for our development environment; our production environment will be ActiveRecord with Oracle, with transactions imported/synchronized to SAP via EAI conduit to BAPI/RFC invocation on an hourly interval.
We need to be able to audit models and its associated object changes. We require the ability to audit updates/deletions, recording a whodunit log for each revision, e.g, invoices, invoice lines; if I delete an invoice line in version 3, and add two invoice lines in version 4, and add one more invoice line in version 5, I'd like to be able to pull version 4 exactly as it was).
In short, an auditor must be able to look at a transaction and pull any previous revisions exactly how it looked from our software.
What is the best way to do this? My thinking is in the example of Invoices and InvoiceLines to create a new object called RevisedInvoices and RevisedInvoiceLines and have the database be triggered to copy the model when an update or deletion is called in SQL. On the other hand, I can control the logic better by programming the copy in a before_ hook in the app. Should I do this as a database trigger or should I let the MVC app logic handle the copying?
I know this isn't the most efficient way of building an audit trail since I am making entire copies rather than storing the delta changes for each revision. But since space is cheap, I'd like someone to give me their experience with building an audit trail, especially one with associations. If I change an invoice A with invoice lines B, C, and D, and I add another invoice line E, how can I audit/version associated objects? What do you guys think about cloning the model to a second a table such as a RevisedObject to do the trick?
Please advise.