cubicweb/hooks/syncschema.py
branch3.24
changeset 11904 e760c54490b1
parent 11903 6f36275a6e74
child 12025 ba79f4a4f5d8
equal deleted inserted replaced
11903:6f36275a6e74 11904:e760c54490b1
   776             syssource.update_rdef_column(self.cnx, self.rdef)
   776             syssource.update_rdef_column(self.cnx, self.rdef)
   777         if self.unique_changed:
   777         if self.unique_changed:
   778             syssource.update_rdef_unique(self.cnx, self.rdef)
   778             syssource.update_rdef_unique(self.cnx, self.rdef)
   779 
   779 
   780 
   780 
   781 class CWConstraintAddOp(CWConstraintDelOp):
   781 class CWConstraintAddOp(hook.LateOperation, CWConstraintDelOp):
   782     """actually update constraint of a relation definition"""
   782     """actually update constraint of a relation definition"""
   783     entity = None  # make pylint happy
   783     entity = None  # make pylint happy
   784 
   784 
   785     def precommit_event(self):
   785     def precommit_event(self):
   786         cnx = self.cnx
   786         cnx = self.cnx
   884         # del_entity_type also removes entity's relations
   884         # del_entity_type also removes entity's relations
   885         self.cnx.vreg.schema.del_entity_type(self.etype)
   885         self.cnx.vreg.schema.del_entity_type(self.etype)
   886 
   886 
   887 
   887 
   888 class MemSchemaCWRTypeAdd(MemSchemaOperation):
   888 class MemSchemaCWRTypeAdd(MemSchemaOperation):
   889     """actually add the relation type to the instance's schema"""
   889     """Revert addition of the relation type from the instance's schema if something goes wrong.
       
   890     """
   890     rtypedef = None  # make pylint happy
   891     rtypedef = None  # make pylint happy
   891 
       
   892     def precommit_event(self):
       
   893         self.cnx.vreg.schema.add_relation_type(self.rtypedef)
       
   894 
   892 
   895     def revertprecommit_event(self):
   893     def revertprecommit_event(self):
   896         self.cnx.vreg.schema.del_relation_type(self.rtypedef.name)
   894         self.cnx.vreg.schema.del_relation_type(self.rtypedef.name)
   897 
   895 
   898 
   896 
  1099     __select__ = SyncSchemaHook.__select__ & is_instance('CWRType')
  1097     __select__ = SyncSchemaHook.__select__ & is_instance('CWRType')
  1100     events = ('after_add_entity',)
  1098     events = ('after_add_entity',)
  1101 
  1099 
  1102     def __call__(self):
  1100     def __call__(self):
  1103         rtypedef = self.rtype_def()
  1101         rtypedef = self.rtype_def()
       
  1102         # modify the instance's schema now since we'll usually need the type definition to do
       
  1103         # further thing (e.g. add relation def of this type) but register and operation to revert
       
  1104         # this if necessary
       
  1105         self._cw.vreg.schema.add_relation_type(rtypedef)
  1104         MemSchemaCWRTypeAdd(self._cw, rtypedef=rtypedef)
  1106         MemSchemaCWRTypeAdd(self._cw, rtypedef=rtypedef)
  1105 
  1107 
  1106     def rtype_def(self):
  1108     def rtype_def(self):
  1107         entity = self.entity
  1109         entity = self.entity
  1108         return ybo.RelationType(name=entity.name,
  1110         return ybo.RelationType(name=entity.name,