How to save version history of data warehouse objects in Appengine

I store object A in my data store for appengine. A has an identifier of type Long. I would like to keep a history of all changes made to fields A. What are the best methods for this type of version for entities? I would prefer a solution that works well with subclasses of A and is as automatic as possible.

Thanks!

+8
database google-app-engine versioning datastore
source share
3 answers

You can create a linked list of entities where each object has two links: one to its previous version and one to the next. Of course, you must maintain these links yourself. The latest version of the object will be without a link to the next version (or a blank / null link).

Depending on your use case, you can also look at ways to save the differences between the two versions of the object (if the changes are small and large objects).

+2
source share

We are doing something similar for one of our AppEngine applications. The only effective way we found is to have Entity B, which are your versions, and Entity A stores a list of keys.

Then we use ETags in our REST services to determine which version of our client receives a copy.

0
source share

There are many ways to do this.

If you need one way that does not require more classes in the data model, you can use the parent attribute to write versions and request the ancestor to read the latest version.

Here is an example of how this might work on a wiki page using the ndb.Model and webapp2 framework in Python GAE:

The model may be:

class WikiPage(ndb.Model): title = ndb.StringProperty(required = True) text = ndb.TextProperty(required = True) datetime = ndb.DateTimeProperty(auto_add_now = True) 

The handle may be:

 class Page(webapp2.RequestHandler): def get(self, path): # create the page key from the page id (in this case, the get request path) page_key = ndb.Key('WikiPage', path) # query for edited versions wikipage_edited = WikiPage.query(ancestor=page_key).order(-WikiPage.datetime).get() # check if wikipage have edited versions if wikipage_edited: wikipage = wikipage_edited # if not, get the original version else: wikipage = page_key.get() # some custom function to render the wikipage self.render(wikipage) def post(self): # you can pass some parameter that indicates the page_id being edited page_id = self.request.get('page_id') # check if page_id was sent if page_id: wikipage = WikiPage(parent = ndb.Key('WikiPage', page_id), title = self.request.get('new_title'), text = self.request.get('new_text')) # if page_id wasn't sent, it assumes that a new page is being created else: # some custom function that create a page id in the way you want page_id = self.create_a_page_id() wikipage = WikiPage(id = page_id, title = self.request.get('title'), text = self.request.get('text')) wikipage.put() 
0
source share

All Articles