server/migractions.py
changeset 9636 e35ae8617c03
parent 9635 aaf099172bb9
child 9686 9a04e48e780b
equal deleted inserted replaced
9635:aaf099172bb9 9636:e35ae8617c03
   605             # 1. remove old constraints and update constraints of the same type
   605             # 1. remove old constraints and update constraints of the same type
   606             # NOTE: don't use rschema.constraint_by_type because it may be
   606             # NOTE: don't use rschema.constraint_by_type because it may be
   607             #       out of sync with newconstraints when multiple
   607             #       out of sync with newconstraints when multiple
   608             #       constraints of the same type are used
   608             #       constraints of the same type are used
   609             for cstr in oldconstraints:
   609             for cstr in oldconstraints:
   610                 for newcstr in newconstraints:
   610                 self.rqlexec('DELETE CWConstraint C WHERE C eid %(x)s',
   611                     if newcstr.type() == cstr.type():
   611                              {'x': cstr.eid}, ask_confirm=confirm)
   612                         break
       
   613                 else:
       
   614                     newcstr = None
       
   615                 if newcstr is None:
       
   616                     self.rqlexec('DELETE X constrained_by C WHERE C eid %(x)s',
       
   617                                  {'x': cstr.eid}, ask_confirm=confirm)
       
   618                 else:
       
   619                     newconstraints.remove(newcstr)
       
   620                     value = unicode(newcstr.serialize())
       
   621                     if value != unicode(cstr.serialize()):
       
   622                         self.rqlexec('SET X value %(v)s WHERE X eid %(x)s',
       
   623                                      {'x': cstr.eid, 'v': value},
       
   624                                      ask_confirm=confirm)
       
   625             # 2. add new constraints
   612             # 2. add new constraints
   626             cstrtype_map = self.cstrtype_mapping()
   613             cstrtype_map = self.cstrtype_mapping()
   627             self.rqlexecall(ss.constraints2rql(cstrtype_map, newconstraints,
   614             self.rqlexecall(ss.constraints2rql(cstrtype_map, newconstraints,
   628                                                repordef.eid),
   615                                                repordef.eid),
   629                             ask_confirm=confirm)
   616                             ask_confirm=confirm)