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

3

8

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?

Spock answered 5/4, 2011 at 17:38 Comment(0)
B
2

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.

Bookerbookie answered 6/4, 2011 at 1:24 Comment(0)
D
1

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

Descry answered 5/4, 2011 at 17:50 Comment(0)
S
0

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.

Swirl answered 5/4, 2011 at 18:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.