Many of you are likely familiar with the 'Track Changes' option in a Frappe DocType. But have you ever pondered over the mechanics behind it? Even if you haven't, understanding how it works can be a valuable asset.
When 'Track Changes' is enabled for a DocType, each time a document of that type undergoes an update, a corresponding record is generated in the 'Version' DocType. This record encapsulates the additions, deletions, and modifications made during that specific save instance. The interesting aspect of a 'Version' document lies in its storage format—it preserves the data as a JSON by comparing the document before and after the update. The JSON structure looks like this:
{
"added": [], // Contains newly added data
"changed": [], // Contains modifications with before and after values
"data_import": null,
"removed": [], // Contains removed data
"row_changed": [], // Contains added, changed, and removed data for child table entries
"updater_reference": null
}
Each element encompasses every metadata detail of the modified data upon the document update. Essentially, Versioning acts as a form of backup, though not as user-friendly for restoration with a single click. Despite this, it stands as a powerful feature in Frappe, serving as a fail-safe in case of issues with database backups. While its primary purpose is to visualize document changes for end users, its backup capabilities add an extra layer of reassurance.
No comments yet. Login to start a new discussion Start a new discussion