# HG changeset patch # User Laura Médioni # Date 1409205333 -7200 # Node ID 64b573d54133461e8e7f02cd95f9d2912c1a85fb # Parent cef58bd36f7bf6e7adfd186ac03492060578d24f [CWEP002 migration] support drop_relation_type for computed relations Related to #3546717. diff -r cef58bd36f7b -r 64b573d54133 hooks/syncschema.py --- a/hooks/syncschema.py Thu Aug 28 07:49:31 2014 +0200 +++ b/hooks/syncschema.py Thu Aug 28 07:55:33 2014 +0200 @@ -1063,6 +1063,24 @@ RDefDelOp(cnx, rdef=rdef) +# CWComputedRType hooks ####################################################### + +class DelCWComputedRTypeHook(SyncSchemaHook): + """before deleting a CWComputedRType entity: + * check that we don't remove a core relation type + * instantiate an operation to delete the relation type on commit + """ + __regid__ = 'syncdelcwcomputedrtype' + __select__ = SyncSchemaHook.__select__ & is_instance('CWComputedRType') + events = ('before_delete_entity',) + + def __call__(self): + name = self.entity.name + if name in CORE_TYPES: + raise validation_error(self.entity, {None: _("can't be deleted")}) + MemSchemaCWRTypeDel(self._cw, rtype=name) + + # CWAttribute / CWRelation hooks ############################################### class AfterAddCWAttributeHook(SyncSchemaHook): diff -r cef58bd36f7b -r 64b573d54133 server/migractions.py --- a/server/migractions.py Thu Aug 28 07:49:31 2014 +0200 +++ b/server/migractions.py Thu Aug 28 07:55:33 2014 +0200 @@ -1057,8 +1057,12 @@ def cmd_drop_relation_type(self, rtype, commit=True): """unregister an existing relation type""" - # unregister the relation from CWRType - self.rqlexec('DELETE CWRType X WHERE X name %r' % rtype, + rschema = self.repo.schema[rtype] + if rschema.rule: + etype = 'CWComputedRType' + else: + etype = 'CWRType' + self.rqlexec('DELETE %s X WHERE X name %r' % (etype, rtype), ask_confirm=self.verbosity>=2) if commit: self.commit() diff -r cef58bd36f7b -r 64b573d54133 server/test/unittest_migractions.py --- a/server/test/unittest_migractions.py Thu Aug 28 07:49:31 2014 +0200 +++ b/server/test/unittest_migractions.py Thu Aug 28 07:55:33 2014 +0200 @@ -703,6 +703,12 @@ 'Cannot drop a relation definition for a computed ' 'relation (notes)') + def test_computed_relation_drop_relation_type(self): + self.assertIn('notes', self.schema) + with self.mh() as (cnx, mh): + mh.cmd_drop_relation_type('notes') + self.assertNotIn('notes', self.schema) + if __name__ == '__main__': unittest_main()