[ZODB-Dev] Changing namespace - best strategy

Marius Gedminas marius at gedmin.as
Mon Jul 15 15:54:11 CEST 2013


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
that.)

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

HTH,
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
everything.
-- Karl Lehenbauer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://mail.zope.org/pipermail/zodb-dev/attachments/20130715/c4a25514/attachment.sig>


More information about the ZODB-Dev mailing list