hooks/syncschema.py
changeset 10813 ab626726a70a
parent 10799 ec97974b9010
child 10816 d4a26e94f54a
equal deleted inserted replaced
10812:a747e211266b 10813:ab626726a70a
    35 from logilab.common.decorators import clear_cache
    35 from logilab.common.decorators import clear_cache
    36 
    36 
    37 from cubicweb import validation_error
    37 from cubicweb import validation_error
    38 from cubicweb.predicates import is_instance
    38 from cubicweb.predicates import is_instance
    39 from cubicweb.schema import (SCHEMA_TYPES, META_RTYPES, VIRTUAL_RTYPES,
    39 from cubicweb.schema import (SCHEMA_TYPES, META_RTYPES, VIRTUAL_RTYPES,
    40                              CONSTRAINTS, ETYPE_NAME_MAP, display_name)
    40                              CONSTRAINTS, UNIQUE_CONSTRAINTS, ETYPE_NAME_MAP,
       
    41                              display_name)
    41 from cubicweb.server import hook, schemaserial as ss, schema2sql as y2sql
    42 from cubicweb.server import hook, schemaserial as ss, schema2sql as y2sql
    42 from cubicweb.server.sqlutils import SQL_PREFIX
    43 from cubicweb.server.sqlutils import SQL_PREFIX
    43 from cubicweb.hooks.synccomputed import RecomputeAttributeOperation
    44 from cubicweb.hooks.synccomputed import RecomputeAttributeOperation
    44 
    45 
    45 # core entity and relation types which can't be removed
    46 # core entity and relation types which can't be removed
   747         # so there is nothing to do here
   748         # so there is nothing to do here
   748         if cnx.added_in_transaction(rdefentity.eid):
   749         if cnx.added_in_transaction(rdefentity.eid):
   749             return
   750             return
   750         rdef = self.rdef = cnx.vreg.schema.schema_by_eid(rdefentity.eid)
   751         rdef = self.rdef = cnx.vreg.schema.schema_by_eid(rdefentity.eid)
   751         cstrtype = self.entity.type
   752         cstrtype = self.entity.type
   752         oldcstr = self.oldcstr = rdef.constraint_by_type(cstrtype)
   753         if cstrtype in UNIQUE_CONSTRAINTS:
       
   754             oldcstr = self.oldcstr = rdef.constraint_by_type(cstrtype)
       
   755         else:
       
   756             oldcstr = None
   753         newcstr = self.newcstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value)
   757         newcstr = self.newcstr = CONSTRAINTS[cstrtype].deserialize(self.entity.value)
   754         # in-place modification of in-memory schema first
   758         # in-place modification of in-memory schema first
   755         _set_modifiable_constraints(rdef)
   759         _set_modifiable_constraints(rdef)
   756         newcstr.eid = self.entity.eid
   760         newcstr.eid = self.entity.eid
   757         if oldcstr is not None:
   761         if oldcstr is not None: