I have to write Java application working with Postgres, where I will be storing Text files. I need to have functionality to do gitlike commit/revert, so I created first goals to achieve:
- commit from program will write document with info about latest change owner, date and create something like log or log file in database - HERE IS MY QUESTION :)
- revert will have parameter (commit ID) and using log/diff file it will revert all changes
So, my question is
- how can I create meaningful, not so poor performance system like this? I was thinking about creating PL/pgSQL function as trigger on UPDATE/DELETE in my table. Log would be created in function and stored in auxiliary table. It is good solution or sooo simple and performance poor?
- Can you advice me any good solution for creating difference log? I mean something easy to look at by human (like in GIT) and easy to use by revert functionality.
My thoughts of last few minutes:
CREATE TABLE logs(
operationID int NOT NULL UNIQUE,
operationType text NOT NULL,
applyData timestamp NOT NULL,
comment text,
userID int NOT NULL,
logText NOT NULL,
--etc.
);
CREATE TRIGGER logChanges
AFTER UPDATE OR DELETE ON myAwesomeTable
(for affectedRow) ROW EXECUTE EXECUTE PROCEDURE loggingProcedure();