-2

problem:

I want to develop a log management system that has the following features: 1- All logs collect from a queue and sequentially add to database 2- The data log can only be added and the system does not allow the user to edit it. 3- If the log data is changed through the database or a log data is deleted, the system must be able to recognize this change.

my solution: I'm serializing the log to Json. Then I calculate the hash(log+ the hash of the previous log) and store it for that log. To detect the change, I repeat this method and compare the calculated hash with the stored hash. If it was different, it indicates a change. But this method sometimes does not work properly. Without any change in the data, a different hash is calculated.

Do you have a better idea?

1 Answers1

2

1.You can save hash of sum of hash value of each row in other table and update it when new row has added.

var hashOfHashes = hash(row1.hash + row2.hash +...);

2.Other solution for better performance is to prevent deleting row by trigger like this answer Trigger to prevent Any Deleting from Table or Trigger to prevent Any Deleting from Table.

CREATE OR ALTER TRIGGER triggerName
ON tableName
INSTEAD OF DELETE
AS
BEGIN
  RAISERROR ('Deletion not supported on this table',16,1);
END;

If you use Ef Core this persian post can help you.

balazadeh
  • 71
  • 4