[migractions] don't commit in the middle of drop_cube

If we've removed only part of the cube's schema, we might be in an inconsistent state, and commit might very well fail.

authorJulien Cristau <julien.cristau@logilab.fr>
changesetaee403cf2552
branchdefault
phasedraft
hiddenno
parent revision#3c66c31ebdd2 fix: UX when migractions failed to get its connection
child revision<not specified>
files modified by this revision
cubicweb/server/migractions.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1438875100 -7200
# Thu Aug 06 17:31:40 2015 +0200
# Node ID aee403cf255213cf96e1857eb225333b12795051
# Parent 3c66c31ebdd2394ea6a254563c8bb662004aaf7e
[migractions] don't commit in the middle of drop_cube

If we've removed only part of the cube's schema, we might be in an
inconsistent state, and commit might very well fail.

diff --git a/cubicweb/server/migractions.py b/cubicweb/server/migractions.py
@@ -714,30 +714,30 @@
1          for cube in reversed(removedcubes):
2              self.cmd_exec_event_script('preremove', cube)
3          # remove cubes'entity and relation types
4          for rschema in fsschema.relations():
5              if rschema not in removedcubes_schema and rschema in reposchema:
6 -                self.cmd_drop_relation_type(rschema.type)
7 +                self.cmd_drop_relation_type(rschema.type, commit=False)
8          toremove = [eschema for eschema in fsschema.entities()
9                      if eschema not in removedcubes_schema and eschema in reposchema]
10          for eschema in reversed(order_eschemas(toremove)):
11 -            self.cmd_drop_entity_type(eschema.type)
12 +            self.cmd_drop_entity_type(eschema.type, commit=False)
13          for rschema in fsschema.relations():
14              if rschema in removedcubes_schema and rschema in reposchema:
15                  # check if attributes/relations has been added to entities from
16                  # other cubes
17                  for fromtype, totype in rschema.rdefs:
18                      if (fromtype, totype) not in removedcubes_schema[rschema.type].rdefs and \
19                         (fromtype, totype) in reposchema[rschema.type].rdefs:
20                          self.cmd_drop_relation_definition(
21 -                            str(fromtype), rschema.type, str(totype))
22 +                            str(fromtype), rschema.type, str(totype), commit=False)
23          # execute post-remove files
24          for cube in reversed(removedcubes):
25              self.cmd_exec_event_script('postremove', cube)
26              self.rqlexec('DELETE CWProperty X WHERE X pkey %(pk)s',
27                           {'pk': u'system.version.' + cube}, ask_confirm=False)
28 -            self.commit()
29 +        self.commit()
30 
31      # schema migration actions ################################################
32 
33      def cmd_add_attribute(self, etype, attrname, attrtype=None, commit=True):
34          """add a new attribute on the given entity type"""