Update product price beyond update data only

When can previous data not be updated? Example: I have a sales system, where it already has records made such as product and product value, let’s assume that the price of the product has been updated and I cannot lose the record of old prices, I want you to update the next ones from the update date , is this possible in Bubble?

Yes you would setup a Database Trigger with a condition checking if the Product’s price before change is different than price after change. Then create a new Price History item saving the previous amount, new amount, and reference to the Product (field type Product).

This could be expanded to track any changes about a Product as well, like if the name or picture. Just by adding more “or” conditions and savings more fields.

Expanding the question , what if the history is a user or product view count ? That is if the changes are more frequent I mean. Wouldn’t it be costly ?

Yea sounds costly to create a database item on every page load. I suppose it can be done if it’s worth the trade off knowing who viewed what at all times. Or you could update a view count number of the product on page load if that’s all you need.

Or have some logic so they have to be viewing it for 10 seconds to save to the database that they viewed it