[ZODB-Dev] Schema migration, rename class

Jeremy Hylton jeremy at zope.com
Wed Mar 31 09:38:32 EST 2004


On Wed, 2004-03-31 at 09:19, Syver Enstad wrote:
> I am looking for good resources on schema migration with ZODB. 
> 
> http://www-106.ibm.com/developerworks/linux/library/l-pypers.html
> 
> Shows some of the techniques (the article is about Pickling) The
> article describes how to rename a class by changing the self.__class__
> to the renamed class in __setstate__ but this doesn't seem to work.

(I haven't followed the link yet, but ...)  You can't change the class
of a persistent object, although it may seem like you can because you
can assign to __class__.  The problem is that persistent references
contain the class and oid of the object.  So you can change __class__,
but the next time the object is loaded it will get whatever class its
referrer thinks it has.

I don't know if we have a good answer for changing the class.  My first
guess is that you'd need to write a tool that scanned the entire
database.  You could either do a low-level (pickle-level) translator
against the storage or do an application-level translator that loaded
each object and marked it as changed if it referred to the object that
was changing class.  Neither sounds very appealing.

Jeremy





More information about the ZODB-Dev mailing list