Suppose I want to store users and groups in a MySQL database. They have an n: m ratio. To track all changes, each table has an audit table user_journal, group_journal and user_group_journal. MySQL starts copying the current record to the log table on each INSERT or UPDATE (DELETES are not supported, since I need information that the user of the application deleted, so there is an active flag that will be set to 0 instead of deleting).
My question / problem: I assume that I add 10 users to the group right away. When I later move on to the history of this group in the user interface of the application, I want to add these 10 users as one step , and not as 10 independent steps. Is there a good solution to group such changes? Perhaps there is a counter that increments every time a trigger fires? I have never worked with triggers.
The best solution would be to collect all the changes made as part of the transaction. Therefore, when a user updates the group name and adds 10 users in one step (one call to the form controller), it will be one step in the history. Maybe you can determine a random hash or graft a global counter every time you start a transaction and access this value in a trigger?
I do not want the table design to be more complex than one log table for each "real" table. I do not want to add a transaction hash to each database table (which means "real" tables, not audit tables - that would be fine there, of course). Also, I would like to have the solution in the database, not in the application.
stofl
source share