Problem Statement
I am trying to store a form response to a PostgreSQL table and maintain a version history along with timestamps if someone updates any input (just like what google docs offer, but for a form).
I am using NodeJS and Sequelize ORM in this project and didn't find anything Sequelize offers to solve this problem (did I missed?)
Is this anything natively available or I need implement custom?
Solution 1
(but comes with another problem )
After doing some searches I found PostgreSQL offers a concept of Temporal Tables which uses database trigger and save a dump of previous data before every INSERT, UPDATE, DELETE fired.
But problem with this approach is for some minor update it will create copy of every column of that form response table.
Solution 2
(might be good approach)
The most possible way I can think of is, when some inputs are updated in a form response before updating the row in database, compare the request body with that form response row which is already stored in database with some JSON compare tools like deep-object-diff and save the changes only in a separate table with versioning and timestamps.
Might be a CPU intensive approach but what could be better?