Appengine - Upgrading from Standard DB to NDB - ReferenceProperties

I have an AppEngine application that I am considering to update an NDB database.

In my application, I have millions of objects that have old style db links. I would like to know what the best migration path would be for these ReferenceProperty values ​​to be converted to KeyProperty values ​​or any other solution that would allow me to switch to NDB.

(I hope for something that is not related to the massive batch processing of all the elements in the database and the calculation of KeyProperty based on ReferenceProperty - something elegant would be nice)

Examples of models that I would like to upgrade from db.Model to ndb.Model are as follows:

class UserModel(db.Model): .... class MailMessageModel(db.Model): m_text = db.TextProperty() m_from = db.ReferenceProperty(reference_class = UserModel) m_to = db.ReferenceProperty(reference_class = UserModel) 
+7
source share
1 answer

The good news is, you don’t need to make any changes to your saved data, but ext.db and ndb read and write accurate data.

Here is a quote from the Nit Cheat Sheet :

No changes to the data warehouse required

If you were wondering, despite the various APIs, NDB and the old ext.db package write exactly the same data to Datastore. This means that you don’t need to do any conversion to the data warehouse, and you can happily mix and match NDB and ext.db code if the scheme you use is equivalent. You can even convert between ext.db and NDB keys with ndb.Key.from_old_key () and key.to_old_key () .

The cheat sheet is a great guide to translate your model definitions. For example, modifying MailMessageModel should be as simple as:

before:

 class MailMessage(db.Model): m_text = db.TextProperty() m_from = db.ReferenceProperty(reference_class=UserModel) m_to = db.ReferenceProperty(reference_class=UserModel) 

after

 class MailMessage(ndb.Model): m_text = ndb.TextProperty() m_from = ndb.KeyProperty(kind=UserModel) m_to = ndb.KeyProperty(kind=UserModel) 

I highly recommend using a cheat sheet to help you with your migration.

+11
source

All Articles