Appengine - 从标准数据库升级到NDB - ReferenceProperties [英] Appengine - Upgrading from standard DB to NDB - ReferenceProperties

查看:233
本文介绍了Appengine - 从标准数据库升级到NDB - ReferenceProperties的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AppEngine应用程序,我正在考虑升级以使用NDB数据库。

I have an AppEngine application that I am considering upgrading to use the NDB database.

在我的应用程序中,我有数以百万计的对象具有旧式的数据库引用。我想知道什么最好的迁移路径是将这些ReferenceProperty值转换为KeyProperty值,或任何其他解决方案,将允许我升级到NDB。

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

(我希望不涉及大量批量处理数据库中的所有元素,并计算基于ReferenceProperty的KeyProperty - 一个优雅的东西会很好)

(I am hoping for something that doesn't involve massive batch processing of all of the elements in the database and computing the KeyProperty based on the ReferenceProperty -- something elegant would be nice)

我想从db.Model升级到ndb.Model的模型示例如下:

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

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)


推荐答案

好消息,您不必对持久化数据进行任何更改,因为 ext.db ndb

Good news, you don't have to make any changes to your persisted data, as ext.db and ndb read and write the exact same data.

这是 NDB工具表




如果你想知道,尽管有不同的API,NDB和旧的ext.db包写入完全相同的数据到数据存储。这意味着您不必对数据存储区进行任何转换,并且您可以愉快地混合和匹配NDB和ext.db代码,只要您使用的模式是等效的。您甚至可以使用 ndb.Key.from_old_key在ext.db和NDB键之间进行转换() key.to_old_key()

备忘单是转换模型定义的最佳指南。例如,更改 MailMessageModel 应该像以下一样简单:

The cheat sheet is a great guide to convert your model definitions. For example, changing your MailMessageModel should be as easy as:

之前:

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

之后:

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

我强烈建议使用欺诈以协助您迁移。

I highly recommend using the cheat sheet to assist you with your migration.

这篇关于Appengine - 从标准数据库升级到NDB - ReferenceProperties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆