backport oldstable

authorSylvain Th?nault <sylvain.thenault@logilab.fr>
changeset5ea4bf53eff2
branchstable
phasepublic
hiddenno
parent revision#63f0bc280354 [migration] Lesser memory consumption of cwuri fix + actually commit every 100 processed entities, #9acffa1ecb2f cleanups
child revision#bcdf22734059 Abstract the support for ORDER BY and LIMIT/OFFSET SQL generation
files modified by this revision
misc/migration/3.10.9_Any.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1300969872 -3600
# Thu Mar 24 13:31:12 2011 +0100
# Branch stable
# Node ID 5ea4bf53eff2588b9cf1feb72fec0d7dae442929
# Parent 9acffa1ecb2fbf411d7796f4732066ac2191eb3f
# Parent 63f0bc2803546bf3c3b582707c421c2c697d1d92
backport oldstable

diff --git a/misc/migration/3.10.9_Any.py b/misc/migration/3.10.9_Any.py
@@ -1,29 +1,31 @@
1  from __future__ import with_statement
2  import sys
3 
4 -# fix some corrupted entities noticed on several instances
5 -rql('DELETE CWConstraint X WHERE NOT E constrained_by X')
6 -rql('SET X is_instance_of Y WHERE X is Y, NOT X is_instance_of Y')
7 -commit()
8 +
9 +if confirm('fix some corrupted entities noticed on several instances?'):
10 +    rql('DELETE CWConstraint X WHERE NOT E constrained_by X')
11 +    rql('SET X is_instance_of Y WHERE X is Y, NOT X is_instance_of Y')
12 +    commit()
13 
14  if confirm('fix existing cwuri?'):
15 -    from logilab.common.shellutils import ProgressBar
16 +    from logilab.common.shellutils import progress
17      from cubicweb.server.session import hooks_control
18      rset = rql('Any X, XC WHERE X cwuri XC, X cwuri ~= "%/eid/%"')
19 -    if sys.stdout.isatty():
20 -        pb = ProgressBar(nbops=rset.rowcount, size=70)
21 -    else:
22 -        pb = None
23 -    with hooks_control(session, session.HOOKS_DENY_ALL, 'integrity'):
24 -        for i,  e in enumerate(rset.entities()):
25 -            e.set_attributes(cwuri=e.cwuri.replace('/eid', ''))
26 -            if i % 100: # commit every 100 entities to limit memory consumption
27 -                commit(ask_confirm=False)
28 -            if pb is not None:
29 +    title = "%i entites to fix" % len(rset)
30 +    nbops = rset.rowcount
31 +    enabled = interactive_mode
32 +    with progress(title=title, nbops=nbops, size=30, enabled=enabled) as pb:
33 +        with hooks_control(session, session.HOOKS_DENY_ALL, 'integrity'):
34 +            for i,  row in enumerate(rset):
35 +                data = {'eid': row[0], 'cwuri': row[1].replace(u'/eid', u'')}
36 +                rql('SET X cwuri %(cwuri)s WHERE X eid %(eid)s', data)
37 +                if not i % 100: # commit every 100 entities to limit memory consumption
38 +                    pb.text = "%i committed" % i
39 +                    commit(ask_confirm=False)
40                  pb.update()
41 -    commit(ask_confirm=False)
42 +        commit(ask_confirm=False)
43 
44  try:
45      from cubicweb import devtools
46      option_group_changed('anonymous-user', 'main', 'web')
47      option_group_changed('anonymous-password', 'main', 'web')