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