I'm storing an Entity A in my datastore on appengine. A has an id of type Long. I'd like to keep a history of all changes made to A's fields. What are the best practices to doing this type of version ing on entities? I'd prefer a solution that works well with subclasses of A and is as automatic as possible.
Thanks!
Updating entities To update an existing entity, modify the attributes of the Entity object, then pass it to the DatastoreService. put() method. The object data overwrites the existing entity. The entire object is sent to Datastore with every call to put() .
Data objects in Datastore are known as entities. An entity has one or more named properties, each of which can have one or more values. Entities of the same kind do not need to have the same properties, and an entity's values for a given property do not all need to be of the same data type.
A transaction is a set of Datastore operations on one or more entities in up to 25 entity groups. Each transaction is guaranteed to be atomic, which means that transactions are never partially applied. Either all of the operations in the transaction are applied, or none of them are applied.
const taskKey = datastore. key('Task'); await datastore. delete(taskKey);
You could create a linked list of entities, where each entity has two references: one to its previous version and one to the next version. You have to maintain those references yourself, of course. The most recent version of an entity will be the one without a reference to a next version (or an empty/null reference).
Depending on your use case you might also want to look at ways to only store the differences between two version of an entity (if changes are small and entities are large).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With