I
I
Ivan Melnikov2019-10-23 18:00:38
MySQL
Ivan Melnikov, 2019-10-23 18:00:38

Allow only INSERT in the table for the purpose of logging events?

5db0670744127239071184.png
There is a table ScheduleTest , in which (via the web-face, of course) power engineers in different cities set a schedule for switching on and off street lighting.
There was a task about logging of actions of users in this table.
How good is the next idea? We prohibit UPDATEs and DELETEs. If the user deletes or changes the schedule for a certain date in the web interface, then the record with this date is marked in the active 0 field and a new record is made in the table with this date. When creating a new schedule, the active field is set to 1 by default. As a result, we have access to the entire schedule change history in the schedule worksheet.
ts– the time of the event on the WEB server (for example, deletion or change of the schedule for a certain date),
created – the time the record was created in the table.
My eye blurred. Need a fresh perspective.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor, 2019-10-23
@trooper

I would store the current state of the record (actual) in ScheduleTest, and put the log into a separate table and fill in this table with any change in the record through the trigger, at the output we get a full log of changes.

A
Anton B, 2019-10-23
@bigton

All the same, for logs it is better to make a separate table on INSERT and that's it.
And from your approach in the schedule table, 10 entries will be with active=1, and 90 with active=0

I
Ivan Shumov, 2019-10-23
@inoise

All garbage, the main maneuvers. Read about event log based on CQRS pattern and stop interfering with log data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question