On Mon, Jul 15, 2013 at 03:36:21PM +0200, Pedro Ferreira wrote:
> We need to move a considerable number of persistent objects (~40K) from
> one module to another, and we were wondering what is the best strategy
> to follow.
> Has anyone ever done anything like this? Which approach have you
> followed? Any suggestions?

1. Make sure all the classes are still importable from the old location
   ('from newmodule import MyPersistentSomething # BBB')

That is sufficient to make it work.  If you also want to eradicate all
references to the old module name from your ZODB (e.g. because you'd
like to remove the BBB import), then proceed to step 2:

2. Write a script that loads every instance of this class and does a

   obj._p_activate()  # actually not sure this is required, but won't hurt
   obj._p_changed = True

and then commit the transaction.  Do the commit multiple times, after
each batch of several hundred objects, to avoid excessive memory usage.
Also be sure to handle conflict errors and retry that batch if you're
running this script on the live system.  Finding all instances is left
as an exercise for the reader (sometimes findObjectsProviding() helps,
if you use nested containers everywhere; sometimes application-specific
logic works best; sometimes you end up having to use ZODB iterators to
loop through every single object in the DB -- I believe zodbupdate does

3. (Optional) Remove the BBB import added in step 1.

Marius Gedminas
Voodoo Programming:  Things programmers do that they know shouldn't work but
they try anyway, and which sometimes actually work, such as recompiling
-- Karl Lehenbauer

Attachment: signature.asc
Description: Digital signature

For more information about ZODB, see http://zodb.org/

ZODB-Dev mailing list  -  ZODB-Dev@zope.org

Reply via email to