How to migrate from db.model to ndb.model?

113 views Asked by At

I have an old gae app that uses db.model. I understand that I should migrate to ndb.model. Is there an easy way or must I make many changes?

My code is fairly large and I have an old model that is db.model that I use to build index and search. Should I keep the old model and make a new ndb model or try and change the old model?

Some of the variables in the model are

cities = db.ListProperty(db.Key) #ndb.KeyProperty(repeated=True)
regions = db.ListProperty(db.Key) #ndb.KeyProperty(repeated=True)
blobs = db.ListProperty(db.BlobKey)  #ndb.BlobProperty(repeated=True)
primary_image = blobstore.BlobReferenceProperty()
usr = db.ReferenceProperty()  # ndb_model.KeyProperty()
hasimages = db.BooleanProperty(default=False,
                               verbose_name='has_images')
userID = db.StringProperty(verbose_name='User ID')
integer_price = db.IntegerProperty()
ip = ndb.StringProperty(verbose_name='ip')
ipcountry = db.StringProperty(indexed=False, verbose_name='origin')
tags = db.ListProperty(db.Category)
category = db.CategoryProperty(verbose_name='Category')
title = db.StringProperty(verbose_name='title')  # required
user = db.UserProperty(verbose_name='userid')
im = db.IMProperty(verbose_name='nickname')  # optional, xmpp
city = db.StringProperty()  # postaladdress should work instead
region = db.StringProperty()  # postaladdress should work instead
url = db.StringProperty(verbose_name='url')
geopt = db.GeoPtProperty(verbose_name='geopt')
text = db.TextProperty(verbose_name='text')
1

There are 1 answers

1
Tim Dierks On

It shouldn't be particularly complex, and can be done incrementally, as you can mix db and ndb code in the same binary. See DB to NDB Client Library Migration.