186 # do this last ! |
186 # do this last ! |
187 hook.Operation.__init__(self, session, **kwargs) |
187 hook.Operation.__init__(self, session, **kwargs) |
188 # every schema operation is triggering a schema update |
188 # every schema operation is triggering a schema update |
189 MemSchemaNotifyChanges(session) |
189 MemSchemaNotifyChanges(session) |
190 |
190 |
191 def prepare_constraints(self, subjtype, rtype, objtype): |
191 def prepare_constraints(self, rdef): |
192 rdef = rtype.rdef(subjtype, objtype) |
192 # if constraints is already a list, reuse it (we're updating multiple |
193 constraints = rdef.constraints |
193 # constraints of the same rdef in the same transactions |
194 self.constraints = list(constraints) |
194 if not isinstance(rdef.constraints, list): |
195 rdef.constraints = self.constraints |
195 rdef.constraints = list(rdef.constraints) |
|
196 self.constraints = rdef.constraints |
196 |
197 |
197 |
198 |
198 class MemSchemaEarlyOperation(MemSchemaOperation): |
199 class MemSchemaEarlyOperation(MemSchemaOperation): |
199 def insert_index(self): |
200 def insert_index(self): |
200 """schema operation which are inserted at the begining of the queue |
201 """schema operation which are inserted at the begining of the queue |
547 self.session, table, column, unique=True) |
548 self.session, table, column, unique=True) |
548 |
549 |
549 |
550 |
550 class SourceDbCWConstraintDel(hook.Operation): |
551 class SourceDbCWConstraintDel(hook.Operation): |
551 """actually remove a constraint of a relation definition""" |
552 """actually remove a constraint of a relation definition""" |
552 rtype = subjtype = objtype = None # make pylint happy |
553 rtype = subjtype = None # make pylint happy |
553 |
554 |
554 def precommit_event(self): |
555 def precommit_event(self): |
555 cstrtype = self.cstr.type() |
556 cstrtype = self.cstr.type() |
556 table = SQL_PREFIX + str(self.subjtype) |
557 table = SQL_PREFIX + str(self.subjtype) |
557 column = SQL_PREFIX + str(self.rtype) |
558 column = SQL_PREFIX + str(self.rtype) |
669 # so there is nothing to do here |
670 # so there is nothing to do here |
670 if self.session.added_in_transaction(rdef.eid): |
671 if self.session.added_in_transaction(rdef.eid): |
671 self.cancelled = True |
672 self.cancelled = True |
672 return |
673 return |
673 rdef = self.session.vreg.schema.schema_by_eid(rdef.eid) |
674 rdef = self.session.vreg.schema.schema_by_eid(rdef.eid) |
|
675 self.prepare_constraints(rdef) |
674 subjtype, rtype, objtype = rdef.as_triple() |
676 subjtype, rtype, objtype = rdef.as_triple() |
675 self.prepare_constraints(subjtype, rtype, objtype) |
|
676 cstrtype = self.entity.type |
677 cstrtype = self.entity.type |
677 self.cstr = rtype.rdef(subjtype, objtype).constraint_by_type(cstrtype) |
678 self.cstr = rtype.rdef(subjtype, objtype).constraint_by_type(cstrtype) |
678 self.newcstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value) |
679 self.newcstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value) |
679 self.newcstr.eid = self.entity.eid |
680 self.newcstr.eid = self.entity.eid |
680 |
681 |
692 |
693 |
693 has to be called before SourceDbCWConstraintDel |
694 has to be called before SourceDbCWConstraintDel |
694 """ |
695 """ |
695 rtype = subjtype = objtype = None # make pylint happy |
696 rtype = subjtype = objtype = None # make pylint happy |
696 def precommit_event(self): |
697 def precommit_event(self): |
697 self.prepare_constraints(self.subjtype, self.rtype, self.objtype) |
698 self.prepare_constraints(self.rdef) |
698 |
699 |
699 def commit_event(self): |
700 def commit_event(self): |
700 self.constraints.remove(self.cstr) |
701 self.constraints.remove(self.cstr) |
701 |
702 |
702 |
703 |
1092 try: |
1093 try: |
1093 cstr = rdef.constraint_by_type(entity.type) |
1094 cstr = rdef.constraint_by_type(entity.type) |
1094 except IndexError: |
1095 except IndexError: |
1095 self._cw.critical('constraint type no more accessible') |
1096 self._cw.critical('constraint type no more accessible') |
1096 else: |
1097 else: |
1097 subjtype, rtype, objtype = rdef.as_triple() |
1098 SourceDbCWConstraintDel(self._cw, cstr=cstr, |
1098 SourceDbCWConstraintDel(self._cw, subjtype=subjtype, rtype=rtype, |
1099 subjtype=rdef.subject, rtype=rdef.rtype) |
1099 objtype=objtype, cstr=cstr) |
1100 MemSchemaCWConstraintDel(self._cw, rdef=rdef, cstr=cstr) |
1100 MemSchemaCWConstraintDel(self._cw, subjtype=subjtype, rtype=rtype, |
|
1101 objtype=objtype, cstr=cstr) |
|
1102 |
1101 |
1103 |
1102 |
1104 # permissions synchronization hooks ############################################ |
1103 # permissions synchronization hooks ############################################ |
1105 |
1104 |
1106 class AfterAddPermissionHook(SyncSchemaHook): |
1105 class AfterAddPermissionHook(SyncSchemaHook): |