[ZODB-Dev] Clean way to iterate over all oids/objects in a Storage?

Pieter Nagel pieter@nagel.co.za
26 Aug 2002 19:29:56 +0200


I am writing a migration framework for ZODB applications, and quite
often I need to iterate over all oids in a Storage.

I can do this with a FileStorage by simply iterating over
conn._storage._index.keys(), but is there a way of doing this no matter
what the underlying Storage is?

I would like to make this framework publically available, and it would
be nice if it were more general.

The philosophy of the framework is to atomically migrate an entire DB,
so that one can write invariants for what objects look like instead of
writing __setstate__ methods that can handle arbitrary old versions of
objects that may still lie around because they were never touched for
unpickling yet. 

In this context, I need to iterate over all objects for two reasons:

1) in order to sweep through all objects in a database and call
integrity-checking methods on them, to verify that the databse is in a
consistent state after migration. (This can be thought of as unit-tests
for both one's live production data and one's migration code)

2) in order to find all instances of a certain class, to help writing
migration methods for objects like Date or Money for which there
typically is no simple traversal path from the database's root.

-- 
     ,_
     /_)              /| /
    /   i e t e r    / |/ a g e l
    http://www.nagel.co.za