I would like to create audit tables in my RoR/mysql app. I would like to start out auditing just about everything: every change in the database should result in a row in (one or more) audit tables. My app requires login, so I would like to include the user_id in all entries.
Is there a good starting point for this or should I simply design the table(s), build triggers, etc.?
I would like to create audit tables in my RoR/mysql app. I would like to
start out auditing just about everything: every change in the database
should result in a row in (one or more) audit tables. My app requires
login, so I would like to include the user_id in all entries.
Is there a good starting point for this or should I simply design the
table(s), build triggers, etc.?
You need to learn about AR's callbacks
(ActiveRecord::Callbacks),
which are "hooks" where you can add the auditing code.
Also, google for "rails created_by" for some articles related to the
issue of getting the user id. It's not as easy as it looks, because
the model code (where the callbacks are) doesn't really have access to
the controller (where the user id is). It can be done (I'm doing it),
but you need to read up on the various considerations, especially
thread-safety.
I have a similar requirement as I'm working on a database system for
clinical trials. I've investigated the plugins mentioned but I wasn't
too comfortable for many reasons, especially with the ability to
reconstruct from audit trail.
I'm actually looking into extending the ActiveRecord.