[migration] Avoid unnecessary intermediary commit when migrating a schema 3.24
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 19 Jan 2017 11:10:47 +0100
branch3.24
changeset 11905 2f36115d38b1
parent 11904 e760c54490b1
child 11906 51057823b528
[migration] Avoid unnecessary intermediary commit when migrating a schema Those are low-hanging fruit following changes in ac74476d686c (Fix addition of entity type including boundary constraints on its own attributes): this is no more necesary to commit the get a new relation type definition in the schema. At some point we could/should probably do more on this topic to avoid intermediary commit on e.g. entity type addition, but this requires more work.
cubicweb/server/migractions.py
--- a/cubicweb/server/migractions.py	Wed Jan 18 15:04:27 2017 +0100
+++ b/cubicweb/server/migractions.py	Thu Jan 19 11:10:47 2017 +0100
@@ -666,7 +666,7 @@
         # add new entity and relation types
         for rschema in newcubes_schema.relations():
             if rschema not in self.repo.schema:
-                self.cmd_add_relation_type(rschema.type)
+                self.cmd_add_relation_type(rschema.type, commit=False)
                 new.add(rschema.type)
         toadd = [eschema for eschema in newcubes_schema.entities()
                  if eschema not in self.repo.schema]
@@ -873,7 +873,7 @@
                         # need to add the relation type and to commit to get it
                         # actually in the schema
                         added.append(rschema.type)
-                        self.cmd_add_relation_type(rschema.type, False, commit=True)
+                        self.cmd_add_relation_type(rschema.type, False, commit=False)
                         rtypeadded = True
                     # register relation definition
                     # remember this two avoid adding twice non symmetric relation
@@ -897,7 +897,7 @@
                     if not rtypeadded:
                         # need to add the relation type and to commit to get it
                         # actually in the schema
-                        self.cmd_add_relation_type(rschema.type, False, commit=True)
+                        self.cmd_add_relation_type(rschema.type, False, commit=False)
                         rtypeadded = True
                     elif (targettype, rschema.type, etype) in added:
                         continue
@@ -1096,7 +1096,7 @@
                                 ' do you really want to drop it?' % oldname,
                                 default='n'):
                 return
-        self.cmd_add_relation_type(newname, commit=True)
+        self.cmd_add_relation_type(newname, commit=False)
         if not self.repo.schema[oldname].rule:
             self.rqlexec('SET X %s Y WHERE X %s Y' % (newname, oldname),
                          ask_confirm=self.verbosity >= 2)
@@ -1111,7 +1111,7 @@
             raise ExecutionError('Cannot add a relation definition for a '
                                  'computed relation (%s)' % rschema)
         if rtype not in self.repo.schema:
-            self.cmd_add_relation_type(rtype, addrdef=False, commit=True)
+            self.cmd_add_relation_type(rtype, addrdef=False, commit=False)
         if (subjtype, objtype) in self.repo.schema.rschema(rtype).rdefs:
             print('warning: relation %s %s %s is already known, skip addition' % (
                 subjtype, rtype, objtype))