使用对象数据库时,如何处理对象模型的重大更改?
如果您使用对象数据库,当您需要更改对象模型的结构时会发生什么?
例如,我正在使用 Google App Engine。在开发应用程序时,我意识到在某些情况下,我错误地命名了类,并且我想更改名称。我有两门课我认为我需要巩固。
但是,我认为我不能,因为类的名称直观地与数据存储相关联,并且这些类名称下存储有实际数据。
我认为从数据存储中抽象对象模型的“旧方法”的好处是数据存储对对象模型一无所知——它只是数据。因此,您可以更改对象模型并以不同的方式从数据存储中加载数据。
因此,一般来说,当使用与您的数据模型密切相关的数据存储时……您如何改变一切?
If you use an object database, what happens when you need to change the structure of your object model?
For instance, I'm playing around with the Google App Engine. While I'm developing my app, I've realized that in some cases, I mis-named a class, and I want to change the name. And I have two classes that I think I need to consolidate.
However,I don't think I can, because the name of the class in intuitively tied into the datastore, and there is actual data stored under those class names.
I suppose the good thing about the "old way" of abstracting the object model from the data storage is that the data storage doesn't know anything about the object model --it's just data. So, you can change your object model and just load the data out of the datastore differently.
So, in general, when using a datastore which is intimate with your data model...how do you change things around?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您只关心类命名,则可以更改类名而不更改种类(数据存储中使用的标识符):
如果您想重命名类,只需实现 kind()< /code> 方法如上所述,并让它返回旧的种类名称。
如果您需要更改数据存储区中数据的实际表示形式,则必须运行 mapreduce 更新旧数据。
If it's just class naming you're concerned about, you can change the class name without changing the kind (the identifier that is used in the datastore):
If you want to rename your class, just implement the
kind()
method as above, and have it return the old kind name.If you need to make changes to the actual representation of data in the datastore, you'll have to run a mapreduce to update the old data.
与在关系数据库中执行此操作的方式相同,只不过没有简单的 SQL 脚本:http:// /code.google.com/appengine/articles/update_schema.html
此外,就像过去一样,没有属性的对象不会自动获取默认值,架构中不存在的属性仍然以幻像形式存在在物体中。
要重命名属性,我希望您可以删除旧属性(幻影悬挂在周围)添加新名称,使用旧(幻影)属性的副本填充数据。重写的对象只会有新的属性
The same way you do it in relational databases, except without a nice simple SQL script: http://code.google.com/appengine/articles/update_schema.html
Also, just like the old days, objects without properties don't automatically get defaults and properties that don't exist in the schema still hang around as phantoms in the objects.
To rename a property, I expect you can remove the old property (the phantom hangs around) add the new name, populate the data with a copy from the old (phantom) property. The re-written object will only have the new property
您可以按照我们在项目中的方式进行操作:
在更新对象模型(架构)之前,我们使用自定义导出函数和顶部版本标记将数据导出到 json 格式的文件或 blob 。更新架构后,我们使用另一个自定义函数导入 json,该函数创建新实体并用旧数据填充它们。当然导入版本需要知道与每个版本号关联的json格式。
You may be able to do it the way we are doing it in our project:
Before we update the object-model (schema), we export our data to a file or blob in json format using a custom export function and version tag on top. After the schema has been updated we import the json with another custom function which creates new entities and populates them with old data. Of course the import version needs to know the json format associated with each version number.