Java – best way to update Google datastore with new fields

google-app-enginegoogle-cloud-datastorejava

I have to add new fields to existing tables. After I add the fields , the application breaks as old records do not have newly added field and throw exception. Is there a way to update all old records with newly added fields?

I need it for a java application on google app engine?

Best Answer

Though, I have not come across a strategy to update a model in the datastore, according to my expreiences. You have two options:

  1. Update the existing rows in the datastore with default/null values for the newly added columns

  2. Add a version based fetch function. For ex: Use a try catch block to fetch a newly added column, if it throws an exception, in the catch block, write a routine that will return version 1 of the datastore object. A migration object of sorts.