server/migractions.py
changeset 7562 cdef82ca9eab
parent 7514 32081892850e
parent 7558 044135305359
child 7780 a1d5365fefc1
--- a/server/migractions.py	Thu Jun 23 07:41:25 2011 +0200
+++ b/server/migractions.py	Mon Jun 27 15:30:52 2011 +0200
@@ -739,9 +739,15 @@
 
         `attrname` is a string giving the name of the attribute to drop
         """
-        rschema = self.repo.schema.rschema(attrname)
-        attrtype = rschema.objects(etype)[0]
-        self.cmd_drop_relation_definition(etype, attrname, attrtype, commit=commit)
+        try:
+            rschema = self.repo.schema.rschema(attrname)
+            attrtype = rschema.objects(etype)[0]
+        except KeyError:
+            print 'warning: attribute %s %s is not known, skip deletion' % (
+                etype, attrname)
+        else:
+            self.cmd_drop_relation_definition(etype, attrname, attrtype,
+                                              commit=commit)
 
     def cmd_rename_attribute(self, etype, oldname, newname, commit=True):
         """rename an existing attribute of the given entity type
@@ -774,8 +780,9 @@
         """
         instschema = self.repo.schema
         eschema = self.fs_schema.eschema(etype)
-        assert eschema.final or not etype in instschema, \
-               '%s already defined in the instance schema' % etype
+        if etype in instschema and not (eschema.final and eschema.eid is None):
+            print 'warning: %s already known, skip addition' % etype
+            return
         confirm = self.verbosity >= 2
         groupmap = self.group_mapping()
         cstrtypemap = self.cstrtype_mapping()
@@ -1003,6 +1010,10 @@
 
         """
         reposchema = self.repo.schema
+        if rtype in reposchema:
+            print 'warning: relation type %s is already known, skip addition' % (
+                rtype)
+            return
         rschema = self.fs_schema.rschema(rtype)
         execute = self._cw.execute
         # register the relation into CWRType and insert necessary relation
@@ -1069,6 +1080,10 @@
         rschema = self.fs_schema.rschema(rtype)
         if not rtype in self.repo.schema:
             self.cmd_add_relation_type(rtype, addrdef=False, commit=True)
+        if (subjtype, objtype) in self.repo.schema.rschema(rtype).rdefs:
+            print 'warning: relation %s %s %s is already known, skip addition' % (
+                subjtype, rtype, objtype)
+            return
         execute = self._cw.execute
         rdef = self._get_rdef(rschema, subjtype, objtype)
         ss.execschemarql(execute, rdef,