cubicweb_seda/migration/0.13.0_Any.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 13 Dec 2017 09:54:16 +0100
changeset 2926 9d8dcc178c64
parent 2896 ce08a5c6e100
permissions -rw-r--r--
[migration] Don't ask_confirm to commit this is so annoying.

from cubicweb_seda.xsd2yams import MULTIPLE_CHILDREN

add_relation_type('ordering')

parent_rtypes = [rtype for _, rtype in MULTIPLE_CHILDREN]

for rtype in parent_rtypes:
    for peid, in rql('Any P GROUPBY P WHERE X {} P HAVING COUNT(X) > 1'.format(rtype)):
        for idx, child in enumerate(rql('Any X WHERE X {} P, P eid %(p)s'.format(rtype),
                                    {'p': peid}).entities()):
            child.cw_set(ordering=idx + 1)
    commit(ask_confirm=False)

rql('SET X ordering 1 WHERE X ordering NULL')

commit(ask_confirm=False)