[Zope] Zope Products and keeping existing objects uptodate

Craeg K. Strong cstrong@arielpartners.com
Mon, 07 Jan 2002 22:40:44 -0500


What you are talking about is "schema migration"
That is, migrating already existing instances of an object to a new 
class definition.
Here's how we did it:
- Create a method in your class called "repair()"  It takes no 
arguments, and makes all of the
  changes necessary to change an old version to a new version.

- Create a "repairAll()" python script in the root folder

- execute the repairAll() script (easy way is to use the "test" tab). 
 It recursively
calls the repair() method on all instances of the class.

- presto!   All instances are now up to date.

Here is our repairAll() script:

> """
> $RCSfile: repairAll.py,v $
>
> CVS File Path: $TOP/com/arielpartners/zope/scripts/repairAll.py
>
> Finds all the objects of a given meta-type and calls their "repair"
> method. Good for migrating objects to a new version of a class or
> adding/deleting attributes (schema migration)
>
> Standard Zope Parameters:
> context
>               The object on which the script is being called, also
>               known as the "acquisition parent" of the script. This
>               may be the container, but varies according to the path
>               through which the script is accessed.
> container
>               The Folder in which this script is located. This doesn't
>               change unless you move the script. If the script is in a
>               ZClass, the Container is the class instance.
> script
>               The script object itself
> namespace
>               When the script is called from DTML, this is the
>               caller's DTML namespace, otherwise it is an empty
>               namespace.
> traverse_subpath
>               When the script is published directly from a URL, this
>               is the portion of the URL path after the script's name,
>               split at slash separators into a list of
>               strings. Otherwise, it is an empty list.
>
> Special Parameters:
> metaType      The type of object to change.  For example 'XML Document'
>
> Author: <a href="mailto:cmorris@arielpartners.com">Chip Morris</a>
> Release: 1.0
> """
>
> objects = context.ZopeFind(context, obj_metatypes=[metaType], 
> search_sub=1)
> map(lambda x: x[1].repair(), objects)
> return map(lambda x: x[0], objects)


HTH,

--Craeg

Andreas Leitner wrote:

>Hi,
>
>I am currently experimenting with Zope. My goal is it to implement a
>sort of specialized web-based file server.
>
>My first idea was it to make a plain Product (not ZClass based). Reason
>for this is mainly that I like to controll things. And the Product
>source in my file system allows for an easy and proven way to archive
>the source plus I can put it into cvs.
>
>Now I plan to get a first release of the Product out and then do
>maintainance updates on a regular basis. In the beginning there will be
>only one instance of my Product installed on the customers server -
>which roughly represents one logical file server (there might be added
>more, then each project of my customer will get it's own logical file
>server).
>
>Now, I noticed that when I create an instance of a Product, then change
>the source code of the Product restart Zope the changes won't make it to
>the instance. Zope seems to copy all the dtml pages into it's db. 
>
>Now that does not go well with my plan to do regular updates of the
>Product. Because they won't matter, because the file server will still
>use the old dtml-pages (I have not tested it, but I assume that the
>actual source code will come from the latest version of the product
>only, please correct me if i am wrong).
>
>Is there an easy way to update already existing instances of Products to
>the latest version of the Product?
>
>
>tia,
>Andreas
>
>
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - 
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>

-- 
Craeg K Strong, General Partner
Ariel Partners LLC
voice 781-647-2425
fax   781-647-9690