开发者

When using an object database, how do you handle significant changes to your object model?

开发者 https://www.devze.com 2023-02-22 01:05 出处:网络
If you use an object database, what happens when you need to change the structure of your object model?

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 intuitivel开发者_运维知识库y 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?


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):

class Foo(db.Model):
  @classmethod
  def kind(cls):
    return 'Bar'

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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号