The title nearly says it all. I would like to write a trigger that:
- Uses a table called "audit_trail" with fields
table_name,by,timestamp,operation,contentswherecontentsis in JSON format - The trigger listens for
updateorinserton each table - If the table has a column called
last_modified_by, then:- Make up a JSON version of the record updated/inserted
- Add a record to the
audit_trailtable, with all relevant fields includingcontentswhich would have the JSON representation of the record updated/inserted
Is this technically possible with MySql? I really don't want to code this into the application itself, as it would be messy.
Please note that I am fully aware about the limitation about recording this info as JSON (hard to query, etc.). The only requirement my app has is that an admin must be able to see the "history" of a record, of when/who modified it.
While this is quite trivial, there are things I just cannot work out:
Things I can't work out:
- How do you write a trigger that will get triggered on
insertorupdateon ANY table - How to get the JSON version of a record
- How to get the trigger to store the JSON onto the
contentscolumn
Ideas?