hooks/syncschema.py
changeset 7514 32081892850e
parent 7460 2455cdbeadca
parent 7504 d95f9002edcc
child 7562 cdef82ca9eab
equal deleted inserted replaced
7497:7beb71d76d82 7514:32081892850e
   575                 DropColumn(session, table=SQL_PREFIX + str(rdef.subject),
   575                 DropColumn(session, table=SQL_PREFIX + str(rdef.subject),
   576                            column=SQL_PREFIX + str(rschema))
   576                            column=SQL_PREFIX + str(rschema))
   577         elif lastrel:
   577         elif lastrel:
   578             DropRelationTable(session, str(rschema))
   578             DropRelationTable(session, str(rschema))
   579         # then update the in-memory schema
   579         # then update the in-memory schema
   580         rschema.del_relation_def(rdef.subject, rdef.object)
   580         if rdef.subject not in ETYPE_NAME_MAP and rdef.object not in ETYPE_NAME_MAP:
       
   581             rschema.del_relation_def(rdef.subject, rdef.object)
   581         # if this is the last relation definition of this type, drop associated
   582         # if this is the last relation definition of this type, drop associated
   582         # relation type
   583         # relation type
   583         if lastrel and not session.deleted_in_transaction(rschema.eid):
   584         if lastrel and not session.deleted_in_transaction(rschema.eid):
   584             execute('DELETE CWRType X WHERE X eid %(x)s', {'x': rschema.eid})
   585             execute('DELETE CWRType X WHERE X eid %(x)s', {'x': rschema.eid})
   585 
   586 
   586     def revertprecommit_event(self):
   587     def revertprecommit_event(self):
   587         # revert changes on in memory schema
   588         # revert changes on in memory schema
   588         #
   589         #
   589         # Note: add_relation_def takes a RelationDefinition, not a
   590         # Note: add_relation_def takes a RelationDefinition, not a
   590         # RelationDefinitionSchema, needs to fake it
   591         # RelationDefinitionSchema, needs to fake it
   591         self.rdef.name = str(self.rdef.rtype)
   592         rdef = self.rdef
   592         self.session.vreg.schema.add_relation_def(self.rdef)
   593         rdef.name = str(rdef.rtype)
       
   594         if rdef.subject not in ETYPE_NAME_MAP and rdef.object not in ETYPE_NAME_MAP:
       
   595             self.session.vreg.schema.add_relation_def(rdef)
   593 
   596 
   594 
   597 
   595 
   598 
   596 class RDefUpdateOp(MemSchemaOperation):
   599 class RDefUpdateOp(MemSchemaOperation):
   597     """actually update some properties of a relation definition"""
   600     """actually update some properties of a relation definition"""
   883         # final entities can't be deleted, don't care about that
   886         # final entities can't be deleted, don't care about that
   884         name = self.entity.name
   887         name = self.entity.name
   885         if name in CORE_TYPES:
   888         if name in CORE_TYPES:
   886             raise ValidationError(self.entity.eid, {None: self._cw._('can\'t be deleted')})
   889             raise ValidationError(self.entity.eid, {None: self._cw._('can\'t be deleted')})
   887         # delete every entities of this type
   890         # delete every entities of this type
   888         if not name in ETYPE_NAME_MAP:
   891         if name not in ETYPE_NAME_MAP:
   889             self._cw.execute('DELETE %s X' % name)
   892             self._cw.execute('DELETE %s X' % name)
   890             MemSchemaCWETypeDel(self._cw, etype=name)
   893             MemSchemaCWETypeDel(self._cw, etype=name)
   891         DropTable(self._cw, table=SQL_PREFIX + name)
   894         DropTable(self._cw, table=SQL_PREFIX + name)
   892 
   895 
   893 
   896 
  1067         entity = self.entity
  1070         entity = self.entity
  1068         if self._cw.deleted_in_transaction(entity.eid):
  1071         if self._cw.deleted_in_transaction(entity.eid):
  1069             return
  1072             return
  1070         subjtype = entity.stype.name
  1073         subjtype = entity.stype.name
  1071         objtype = entity.otype.name
  1074         objtype = entity.otype.name
       
  1075         if subjtype in ETYPE_NAME_MAP or objtype in ETYPE_NAME_MAP:
       
  1076             return
  1072         rschema = self._cw.vreg.schema[entity.rtype.name]
  1077         rschema = self._cw.vreg.schema[entity.rtype.name]
  1073         # note: do not access schema rdef here, it may be added later by an
  1078         # note: do not access schema rdef here, it may be added later by an
  1074         # operation
  1079         # operation
  1075         newvalues = {}
  1080         newvalues = {}
  1076         for prop in RelationDefinitionSchema.rproperty_defs(objtype):
  1081         for prop in RelationDefinitionSchema.rproperty_defs(objtype):