server/migractions.py
changeset 7562 cdef82ca9eab
parent 7514 32081892850e
parent 7558 044135305359
child 7780 a1d5365fefc1
equal deleted inserted replaced
7554:fdace9d67d96 7562:cdef82ca9eab
   737     def cmd_drop_attribute(self, etype, attrname, commit=True):
   737     def cmd_drop_attribute(self, etype, attrname, commit=True):
   738         """drop an existing attribute from the given entity type
   738         """drop an existing attribute from the given entity type
   739 
   739 
   740         `attrname` is a string giving the name of the attribute to drop
   740         `attrname` is a string giving the name of the attribute to drop
   741         """
   741         """
   742         rschema = self.repo.schema.rschema(attrname)
   742         try:
   743         attrtype = rschema.objects(etype)[0]
   743             rschema = self.repo.schema.rschema(attrname)
   744         self.cmd_drop_relation_definition(etype, attrname, attrtype, commit=commit)
   744             attrtype = rschema.objects(etype)[0]
       
   745         except KeyError:
       
   746             print 'warning: attribute %s %s is not known, skip deletion' % (
       
   747                 etype, attrname)
       
   748         else:
       
   749             self.cmd_drop_relation_definition(etype, attrname, attrtype,
       
   750                                               commit=commit)
   745 
   751 
   746     def cmd_rename_attribute(self, etype, oldname, newname, commit=True):
   752     def cmd_rename_attribute(self, etype, oldname, newname, commit=True):
   747         """rename an existing attribute of the given entity type
   753         """rename an existing attribute of the given entity type
   748 
   754 
   749         `oldname` is a string giving the name of the existing attribute
   755         `oldname` is a string giving the name of the existing attribute
   772         in auto mode, automatically register entity's relation where the
   778         in auto mode, automatically register entity's relation where the
   773         targeted type is known
   779         targeted type is known
   774         """
   780         """
   775         instschema = self.repo.schema
   781         instschema = self.repo.schema
   776         eschema = self.fs_schema.eschema(etype)
   782         eschema = self.fs_schema.eschema(etype)
   777         assert eschema.final or not etype in instschema, \
   783         if etype in instschema and not (eschema.final and eschema.eid is None):
   778                '%s already defined in the instance schema' % etype
   784             print 'warning: %s already known, skip addition' % etype
       
   785             return
   779         confirm = self.verbosity >= 2
   786         confirm = self.verbosity >= 2
   780         groupmap = self.group_mapping()
   787         groupmap = self.group_mapping()
   781         cstrtypemap = self.cstrtype_mapping()
   788         cstrtypemap = self.cstrtype_mapping()
   782         # register the entity into CWEType
   789         # register the entity into CWEType
   783         execute = self._cw.execute
   790         execute = self._cw.execute
  1001         creation (but not the relation definitions themselves, for which
  1008         creation (but not the relation definitions themselves, for which
  1002         committing depends on the `commit` argument value).
  1009         committing depends on the `commit` argument value).
  1003 
  1010 
  1004         """
  1011         """
  1005         reposchema = self.repo.schema
  1012         reposchema = self.repo.schema
       
  1013         if rtype in reposchema:
       
  1014             print 'warning: relation type %s is already known, skip addition' % (
       
  1015                 rtype)
       
  1016             return
  1006         rschema = self.fs_schema.rschema(rtype)
  1017         rschema = self.fs_schema.rschema(rtype)
  1007         execute = self._cw.execute
  1018         execute = self._cw.execute
  1008         # register the relation into CWRType and insert necessary relation
  1019         # register the relation into CWRType and insert necessary relation
  1009         # definitions
  1020         # definitions
  1010         ss.execschemarql(execute, rschema, ss.rschema2rql(rschema, addrdef=False))
  1021         ss.execschemarql(execute, rschema, ss.rschema2rql(rschema, addrdef=False))
  1067         schema definition file
  1078         schema definition file
  1068         """
  1079         """
  1069         rschema = self.fs_schema.rschema(rtype)
  1080         rschema = self.fs_schema.rschema(rtype)
  1070         if not rtype in self.repo.schema:
  1081         if not rtype in self.repo.schema:
  1071             self.cmd_add_relation_type(rtype, addrdef=False, commit=True)
  1082             self.cmd_add_relation_type(rtype, addrdef=False, commit=True)
       
  1083         if (subjtype, objtype) in self.repo.schema.rschema(rtype).rdefs:
       
  1084             print 'warning: relation %s %s %s is already known, skip addition' % (
       
  1085                 subjtype, rtype, objtype)
       
  1086             return
  1072         execute = self._cw.execute
  1087         execute = self._cw.execute
  1073         rdef = self._get_rdef(rschema, subjtype, objtype)
  1088         rdef = self._get_rdef(rschema, subjtype, objtype)
  1074         ss.execschemarql(execute, rdef,
  1089         ss.execschemarql(execute, rdef,
  1075                          ss.rdef2rql(rdef, self.cstrtype_mapping(),
  1090                          ss.rdef2rql(rdef, self.cstrtype_mapping(),
  1076                                      self.group_mapping()))
  1091                                      self.group_mapping()))