server/migractions.py
branchstable
changeset 9162 bf0a575d8da8
parent 8807 d9aaad2c52e9
child 9164 4415209bea0a
equal deleted inserted replaced
9161:7b51daf84a66 9162:bf0a575d8da8
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
   927 
   927 
   928         `oldname` is a string giving the name of the existing entity type
   928         `oldname` is a string giving the name of the existing entity type
   929         `newname` is a string giving the name of the renamed entity type
   929         `newname` is a string giving the name of the renamed entity type
   930         """
   930         """
   931         schema = self.repo.schema
   931         schema = self.repo.schema
       
   932         if oldname not in schema:
       
   933             print 'warning: entity type %s is unknown, skip renaming' % oldname
       
   934             return
       
   935         # if merging two existing entity types
   932         if newname in schema:
   936         if newname in schema:
   933             assert oldname in ETYPE_NAME_MAP, \
   937             assert oldname in ETYPE_NAME_MAP, \
   934                    '%s should be mapped to %s in ETYPE_NAME_MAP' % (oldname,
   938                    '%s should be mapped to %s in ETYPE_NAME_MAP' % (oldname,
   935                                                                     newname)
   939                                                                     newname)
   936             if attrs is None:
   940             if attrs is None:
  1001                     for sql in sqls:
  1005                     for sql in sqls:
  1002                         self.sqlexec(sql % thiseids, ask_confirm=False)
  1006                         self.sqlexec(sql % thiseids, ask_confirm=False)
  1003             # remove the old type: use rql to propagate deletion
  1007             # remove the old type: use rql to propagate deletion
  1004             self.rqlexec('DELETE CWEType ET WHERE ET name %(on)s', {'on': oldname},
  1008             self.rqlexec('DELETE CWEType ET WHERE ET name %(on)s', {'on': oldname},
  1005                          ask_confirm=False)
  1009                          ask_confirm=False)
       
  1010         # elif simply renaming an entity type
  1006         else:
  1011         else:
  1007             self.rqlexec('SET ET name %(newname)s WHERE ET is CWEType, ET name %(on)s',
  1012             self.rqlexec('SET ET name %(newname)s WHERE ET is CWEType, ET name %(on)s',
  1008                          {'newname' : unicode(newname), 'on' : oldname},
  1013                          {'newname' : unicode(newname), 'on' : oldname},
  1009                          ask_confirm=False)
  1014                          ask_confirm=False)
  1010         if commit:
  1015         if commit: