# HG changeset patch # User Sylvain Thénault # Date 1279637111 -7200 # Node ID eaf8219f8b7d7db3b0205aa69ef2e18d46432b97 # Parent 6c148645075dfbd2e671fe1655308172c3e44b6d [migration] fix rename_entity_type to avoid to loose some relations on the way diff -r 6c148645075d -r eaf8219f8b7d server/checkintegrity.py --- a/server/checkintegrity.py Tue Jul 20 14:09:58 2010 +0200 +++ b/server/checkintegrity.py Tue Jul 20 16:45:11 2010 +0200 @@ -17,8 +17,8 @@ # with CubicWeb. If not, see . """Check integrity of a CubicWeb repository. Hum actually only the system database is checked. +""" -""" from __future__ import with_statement __docformat__ = "restructuredtext en" diff -r 6c148645075d -r eaf8219f8b7d server/migractions.py --- a/server/migractions.py Tue Jul 20 14:09:58 2010 +0200 +++ b/server/migractions.py Tue Jul 20 16:45:11 2010 +0200 @@ -865,23 +865,30 @@ if (rschema.final or rschema.inlined) and not rschema in PURE_VIRTUAL_RTYPES]) self.sqlexec('INSERT INTO %s%s(%s) SELECT %s FROM %s%s' % ( - SQL_PREFIX, newname, attrs, attrs, SQL_PREFIX, oldname)) + SQL_PREFIX, newname, attrs, attrs, SQL_PREFIX, oldname), + ask_confirm=False) # old entity type has not been added to the schema, can't gather it new = schema.eschema(newname) oldeid = self.rqlexec('CWEType ET WHERE ET name %(on)s', {'on': oldname}, ask_confirm=False)[0][0] # backport old type relations to new type # XXX workflows, other relations? - self.rqlexec('SET X from_entity NET WHERE X from_entity OET, ' - 'NOT EXISTS(X2 from_entity NET, X relation_type XRT, X2 relation_type XRT, ' - 'X to_entity XTE, X2 to_entity XTE), ' - 'OET eid %(o)s, NET eid %(n)s', - {'o': oldeid, 'n': new.eid}, ask_confirm=False) - self.rqlexec('SET X to_entity NET WHERE X to_entity OET, ' - 'NOT EXISTS(X2 to_entity NET, X relation_type XRT, X2 relation_type XRT, ' - 'X from_entity XTE, X2 from_entity XTE), ' - 'OET eid %(o)s, NET eid %(n)s', - {'o': oldeid, 'n': new.eid}, ask_confirm=False) + for r1, rr1 in [('from_entity', 'to_entity'), + ('to_entity', 'from_entity')]: + self.rqlexec('SET X %(r1)s NET WHERE X %(r1)s OET, ' + 'NOT EXISTS(X2 %(r1)s NET, X relation_type XRT, ' + 'X2 relation_type XRT, X %(rr1)s XTE, X2 %(rr1)s XTE), ' + 'OET eid %%(o)s, NET eid %%(n)s' % locals(), + {'o': oldeid, 'n': new.eid}, ask_confirm=False) + # backport is / is_instance_of relation to new type + for rtype in ('is', 'is_instance_of'): + self.sqlexec('UPDATE %s_relation SET eid_to=%s WHERE eid_to=%s' + % (rtype, new.eid, oldeid), ask_confirm=False) + # delete relations using SQL to avoid relations content removal + # triggered by schema synchronization hooks + self.sqlexec('DELETE FROM cw_CWRelation ' + 'WHERE cw_from_entity=%(eid)s OR cw_to_entity=%(eid)s', + {'eid': oldeid}, ask_confirm=False) # remove the old type: use rql to propagate deletion self.rqlexec('DELETE CWEType ET WHERE ET name %(on)s', {'on': oldname}, ask_confirm=False)