Search code examples
javagoogle-app-enginerefactoringnosqldatastore

Changing entity-classes problem with development for app-engine


My problem is pretty much obvious:

  1. I had a class named TaskDescription which corresponded to a kind (table) in App Engine Datastore. Then I've renamed it to TaskContent and all stored data is seems to be lost now (because class name which is the so-called kind name is a part of the path to the stored data).
  2. I realize that almost the same problem will occur every time I rename a single field in any entity-class.

Nothing is perfect in this world and I have doubts that it's possible to create all and absolutely correct entities from scratch and never change them after that.

So, how to deal with this issue?


Solution

  • Two ways:

    1. Leave Entities as they are and change the mapping: in objectify you can set the entity to class name mapping: e.g. @Entity(name="EntityName").

    2. Change Entities in the datastore: as datastore is schemaless this can not be done with a simple command. For Entity name change you need to create a new entity, copy all properties and delete the old entity. People usually use a MapReduce jobs to perform datastore maintenance. Here's MapReduce for java.

    For field name changes objectify has explicit support for migrating schemas (there is no schemas, but they still call it that way).