give group mapping where needed
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 08 Dec 2009 16:45:01 +0100
changeset 4043 39ae94e0c8b8
parent 4042 f85a4c846aad
child 4044 3876c894e018
give group mapping where needed
hooks/syncschema.py
server/migractions.py
--- a/hooks/syncschema.py	Tue Dec 08 16:41:43 2009 +0100
+++ b/hooks/syncschema.py	Tue Dec 08 16:45:01 2009 +0100
@@ -57,6 +57,13 @@
         constraints.append(cstr)
     return constraints
 
+def group_mapping(cw):
+    try:
+        return cw.transaction_data['groupmap']
+    except KeyError:
+        cw.transaction_data['groupmap'] = gmap = ss.group_mapping(cw)
+        return gmap
+
 def add_inline_relation_column(session, etype, rtype):
     """add necessary column and index for an inlined relation"""
     table = SQL_PREFIX + etype
@@ -811,7 +818,8 @@
             sampletype = rschema.subjects()[0]
             desttype = rschema.objects()[0]
             props = rschema.rdef(sampletype, desttype)
-            relrqls += list(ss.rdef2rql(rschema, name, desttype, props))
+            relrqls += list(ss.rdef2rql(rschema, name, desttype, props,
+                                        groupmap=group_mapping(self._cw)))
         # now remove it !
         schema.del_entity_type(name)
         # create the necessary table
--- a/server/migractions.py	Tue Dec 08 16:41:43 2009 +0100
+++ b/server/migractions.py	Tue Dec 08 16:45:01 2009 +0100
@@ -691,8 +691,9 @@
         else:
             eschema = self.fs_schema.eschema(etype)
         confirm = self.verbosity >= 2
+        groupmap = self.group_mapping()
         # register the entity into CWEType
-        self.rqlexecall(ss.eschema2rql(eschema, self.group_mapping()), ask_confirm=confirm)
+        self.rqlexecall(ss.eschema2rql(eschema, groupmap), ask_confirm=confirm)
         # add specializes relation if needed
         self.rqlexecall(ss.eschemaspecialize2rql(eschema), ask_confirm=confirm)
         # register entity's attributes
@@ -705,7 +706,8 @@
                 # actually in the schema
                 self.cmd_add_relation_type(rschema.type, False, commit=True)
             # register relation definition
-            self.rqlexecall(ss.rdef2rql(rschema, etype, attrschema.type),
+            self.rqlexecall(ss.rdef2rql(rschema, etype, attrschema.type,
+                                        groupmap=groupmap),
                             ask_confirm=confirm)
         # take care to newly introduced base class
         # XXX some part of this should probably be under the "if auto" block
@@ -766,7 +768,8 @@
                     # remember this two avoid adding twice non symetric relation
                     # such as "Emailthread forked_from Emailthread"
                     added.append((etype, rschema.type, targettype))
-                    self.rqlexecall(ss.rdef2rql(rschema, etype, targettype),
+                    self.rqlexecall(ss.rdef2rql(rschema, etype, targettype,
+                                                groupmap=groupmap),
                                     ask_confirm=confirm)
             for rschema in eschema.object_relations():
                 rtypeadded = rschema.type in instschema or rschema.type in added
@@ -786,7 +789,8 @@
                     elif (targettype, rschema.type, etype) in added:
                         continue
                     # register relation definition
-                    self.rqlexecall(ss.rdef2rql(rschema, targettype, etype),
+                    self.rqlexecall(ss.rdef2rql(rschema, targettype, etype,
+                                                groupmap=groupmap),
                                     ask_confirm=confirm)
         if commit:
             self.commit()
@@ -848,7 +852,8 @@
                         props = rschema.rproperties(
                             rschema.subjects(objtype)[0], objtype)
                         assert props
-                        self.rqlexecall(ss.rdef2rql(rschema, etype, objtype, props),
+                        self.rqlexecall(ss.rdef2rql(rschema, etype, objtype, props,
+                                                    groupmap=self.group_mapping()),
                                         ask_confirm=self.verbosity>=2)
 
         if commit:
@@ -880,7 +885,8 @@
         rschema = self.fs_schema.rschema(rtype)
         if not rtype in self.repo.schema:
             self.cmd_add_relation_type(rtype, addrdef=False, commit=True)
-        self.rqlexecall(ss.rdef2rql(rschema, subjtype, objtype, groupmap=self.group_mapping()),
+        self.rqlexecall(ss.rdef2rql(rschema, subjtype, objtype,
+                                    groupmap=self.group_mapping()),
                         ask_confirm=self.verbosity>=2)
         if commit:
             self.commit()