[migration] we can now specify attributes to backport to rename_entity_type using its attrs argument stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 17 Aug 2010 15:23:59 +0200
branchstable
changeset 6115 56ec278b843e
parent 6114 3e1718a2db55
child 6116 2530e9c45296
[migration] we can now specify attributes to backport to rename_entity_type using its attrs argument
server/migractions.py
--- a/server/migractions.py	Tue Aug 17 15:22:57 2010 +0200
+++ b/server/migractions.py	Tue Aug 17 15:23:59 2010 +0200
@@ -845,7 +845,7 @@
         if commit:
             self.commit()
 
-    def cmd_rename_entity_type(self, oldname, newname, commit=True):
+    def cmd_rename_entity_type(self, oldname, newname, attrs=None, commit=True):
         """rename an existing entity type in the persistent schema
 
         `oldname` is a string giving the name of the existing entity type
@@ -854,11 +854,17 @@
         schema = self.repo.schema
         if newname in schema:
             assert oldname in ETYPE_NAME_MAP, \
-                   '%s should be mappend to %s in ETYPE_NAME_MAP' % (oldname, newname)
-            attrs = ','.join([SQL_PREFIX + rschema.type
-                              for rschema in schema[newname].subject_relations()
-                              if (rschema.final or rschema.inlined)
-                              and not rschema in PURE_VIRTUAL_RTYPES])
+                   '%s should be mapped to %s in ETYPE_NAME_MAP' % (oldname,
+                                                                    newname)
+            if attrs is None:
+                attrs = ','.join(SQL_PREFIX + rschema.type
+                                 for rschema in schema[newname].subject_relations()
+                                 if (rschema.final or rschema.inlined)
+                                 and rschema in schema[oldname].subjrels
+                                 and not rschema in PURE_VIRTUAL_RTYPES)
+            else:
+                attrs += ('eid', 'creation_date', 'modification_date', 'cwuri')
+                attrs = ','.join(SQL_PREFIX + attr for attr in attrs)
             self.sqlexec('INSERT INTO %s%s(%s) SELECT %s FROM %s%s' % (
                 SQL_PREFIX, newname, attrs, attrs, SQL_PREFIX, oldname),
                          ask_confirm=False)