mysqldatabase-designdatabase-diagram

Database Architecture for logging


This is something that has bothered me for a long time and i still have been unable to find an answer.

I have a huge system with alot of different features. What is common for this system is of course that my users can

create, update, read & delete

different parts of my system.

For simple reasons lets say i have an application that has the following features:

(Please do note i took these at random just to prove a point that all of these would have their own separate tables and does not necessarily be connected).

Now i wish to create some sort of logging system. So that when ever someone either create,update or delete an entity it will be recorded.

Now as far as i can see i can do this two ways.

1.

Create a logging table for each of the 4 features that is in my system. However with this method i am required to create a logging table for each new feature i add to the system. i would also have to combine data from X number of tables if i wish to create a log which potentially could be a huge task!

2.

i could create something like the following:

enter image description here

However once again i would have to add a col for each new feature i will add.

So my question is what is the best way for creating logging database architecture

Or is there an easier way?


Solution

  • Instead of one target_xx for each feature, you could do it this way:

    target_id | target_type
    1           video
    4           document
    5           user
    2           user
    

    or even better. A table with target types and insert only the respective id's on target_type

    Something like this:

    enter image description here