hooks/syncschema.py
changeset 10585 80236876ee4d
parent 10035 c5bcdece77fb
child 10586 22f330f829ae
equal deleted inserted replaced
10584:743ed2b13a6f 10585:80236876ee4d
   659         # then update database: alter the physical schema on size/unique
   659         # then update database: alter the physical schema on size/unique
   660         # constraint changes
   660         # constraint changes
   661         syssource = cnx.repo.system_source
   661         syssource = cnx.repo.system_source
   662         cstrtype = self.oldcstr.type()
   662         cstrtype = self.oldcstr.type()
   663         if cstrtype == 'SizeConstraint':
   663         if cstrtype == 'SizeConstraint':
       
   664             # if the size constraint is being replaced with a new max size, we'll
       
   665             # call update_rdef_column in CWConstraintAddOp, skip it here
       
   666             for cstr in cnx.transaction_data.get('newsizecstr', ()):
       
   667                 rdefentity = cstr.reverse_constrained_by[0]
       
   668                 cstrrdef = cnx.vreg.schema.schema_by_eid(rdefentity.eid)
       
   669                 if cstrrdef == rdef:
       
   670                     return
       
   671 
       
   672             # we found that the size constraint for this rdef is really gone,
       
   673             # not just replaced by another
   664             syssource.update_rdef_column(cnx, rdef)
   674             syssource.update_rdef_column(cnx, rdef)
   665             self.size_cstr_changed = True
   675             self.size_cstr_changed = True
   666         elif cstrtype == 'UniqueConstraint':
   676         elif cstrtype == 'UniqueConstraint':
   667             syssource.update_rdef_unique(cnx, rdef)
   677             syssource.update_rdef_unique(cnx, rdef)
   668             self.unique_changed = True
   678             self.unique_changed = True
  1112     __regid__ = 'syncaddcwconstraint'
  1122     __regid__ = 'syncaddcwconstraint'
  1113     __select__ = SyncSchemaHook.__select__ & is_instance('CWConstraint')
  1123     __select__ = SyncSchemaHook.__select__ & is_instance('CWConstraint')
  1114     events = ('after_add_entity', 'after_update_entity')
  1124     events = ('after_add_entity', 'after_update_entity')
  1115 
  1125 
  1116     def __call__(self):
  1126     def __call__(self):
       
  1127         if self.entity.cstrtype[0].name == 'SizeConstraint':
       
  1128             txdata = self._cw.transaction_data
       
  1129             if 'newsizecstr' not in txdata:
       
  1130                 txdata['newsizecstr'] = set()
       
  1131             txdata['newsizecstr'].add(self.entity)
  1117         CWConstraintAddOp(self._cw, entity=self.entity)
  1132         CWConstraintAddOp(self._cw, entity=self.entity)
  1118 
  1133 
  1119 
  1134 
  1120 class AfterAddConstrainedByHook(SyncSchemaHook):
  1135 class AfterAddConstrainedByHook(SyncSchemaHook):
  1121     __regid__ = 'syncaddconstrainedby'
  1136     __regid__ = 'syncaddconstrainedby'