Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consequences for changing a model on Google app engine

SQL Alchemy or Django are by default based on a relational database. Hence any change to the model requires a migration tool such as sqlalchemy-migrate or South.

Now switching to Google App engine and utilizing the ndb, what will happen if I changed a model? Theoretically a NoSQL database such as Big-Table should not care about evolving schema and hence no migration should be required.

However defining a model such as this one, clearly indicates a schema to validate against.

class ExampleModel(ndb.Model):
    example_name = ndb.StringProperty(required=True)
    example_description = ndb.TextProperty(required=True)
    added_by = ndb.UserProperty()
    timestamp = ndb.DateTimeProperty(auto_now_add=True)

So what happens if I added a field? Changed a field or even removed a field?

My assumption is the following:

Adding a field

  • Perhaps the easiest case, only new instances of the model will be validated against the new field. When loading any older instances, the field simply remains empty. However what happens if the field is set as required?

Deleting a field

  • In this case all the older instances will contain orphaned data for the deleted field. But they stay there and will be ignored from now on.

Modifying a field name

  • A combination of the two above; The new name will be regarded as a new field and the old field will be ignored and orphaned.

Is this assumption correct?

like image 489
Houman Avatar asked Jun 23 '13 12:06

Houman


1 Answers

You can find many answers to your questions in the documentation :

Google App Engine - Updating Your Model's Schema

However what happens if the field is set as required?

Setting a property as required only means that you have to set the value directly in the constructor, so existing entities are not affected.

like image 186
Dalmas Avatar answered Sep 30 '22 10:09

Dalmas