Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep version history of datastore entities in Appengine

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!

like image 848
aloo Avatar asked Jun 05 '11 00:06

aloo


People also ask

How do I update entity in Datastore?

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() .

What is Datastore entity?

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.

Is Datastore transactional?

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.

How do I delete a entity in Datastore?

const taskKey = datastore. key('Task'); await datastore. delete(taskKey);


1 Answers

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).

like image 136
Stefan Avatar answered Oct 04 '22 17:10

Stefan