Skip to content Skip to sidebar Skip to footer

Proper Way To Migrate NDB Model Property

I currently have a model in NDB and I'd like to change the property name without necessarily touching NBD. Let's say I have the following: from google.appengine.ext import ndb cla

Solution 1:

you can change the class-level property name while keeping the underlying NDB property name by specifying the name="xx" param in the Property() constructor

so something like this could be done:

class User(ndb.Model):
  company_   = ndb.KeyProperty(name="company", repeated=True)

  @property
  def company(self):
    return self.company_

  @company.setter
  def company(self, new_company):
    self.company_ = new_company

so now anytime you access .company_ NDB will actually set/get "company" internally... and you don't have to do any data migrations


Solution 2:

From my understanding of ndb, the property names are stored in the database along with their contents for every entity. You would have to rewrite every entity with the new property name (and without the old one).

Since that is not pain-free, maybe you could choose other names for your getter and setter like get_company and set_company.


Post a Comment for "Proper Way To Migrate NDB Model Property"