There has been some discussion on the app engine list recently about the best way to handle data migration when your model changes. I thought I'd put together a short summary of some of the options which are open to add, rename, remove or change the type of an existing field.
For the examples here, I'm going to start with a simple model example and gradually change the class. At each stage we can see how the data store handles the change.
We also want some test data. I think one name should be enough here.
Adding a field
Adding a new field is easy enough, we get it set to the default value
Watch out though, until you commit an entity the new field won't be
Renaming a field
How about renaming a field? There is of course no relationship between
To rename a property (in this example birth_date becomes yob), create
The actual renaming is done by picking up the old and new names as
To update the datastore just grab a bunch of objects which have the
Once the migration has been completed we can remove the DummyProperty
If the old field isn't a property which supports sorting then you'll
Removing a field
Removing a field is not a problem, the extra data in the database is
Alternatively we can make it into a dummy property and use the same
Changing field type
If we need to change the type of a property and don't try to handle
Fortunately that can be fixed using __init__ in the same way as a
You can also use this to fixup bad content: if something gets into the