[migration.sync_schema_props_perms] ensure all participants to a unique together constraint are there stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 25 Jul 2013 18:14:56 +0200
branchstable
changeset 9195 e9fb9377229e
parent 9194 4e1946bd9ea2
child 9196 13461cb8ff40
[migration.sync_schema_props_perms] ensure all participants to a unique together constraint are there before adding CWUniqueConstraint. Closes #3038345
server/migractions.py
--- a/server/migractions.py	Thu Jul 25 18:12:28 2013 +0200
+++ b/server/migractions.py	Thu Jul 25 18:14:56 2013 +0200
@@ -575,10 +575,24 @@
                              '      E eid %%(x)s,'
                              '      %s' % ', '.join(restrictions),
                              substs)
+            def possible_unique_constraint(ut):
+                for name in ut:
+                    rschema = repoeschema.subjrels.get(name)
+                    if rschema is None:
+                        print 'dont add %s unique constraint on %s, missing %s' % (
+                            ','.join(ut), eschema, name)
+                        return False
+                    if not (rschema.final or rschema.final.inlined):
+                        (eschema, name)
+                        print 'dont add %s unique constraint on %s, %s is neither final nor inlined' % (
+                            ','.join(ut), eschema, name)
+                        return False
+                return True
             for ut in unique_together - repo_unique_together:
-                rql, substs = ss.uniquetogether2rql(eschema, ut)
-                substs['x'] = repoeschema.eid
-                self.rqlexec(rql, substs)
+                if possible_unique_constraint(ut):
+                    rql, substs = ss.uniquetogether2rql(eschema, ut)
+                    substs['x'] = repoeschema.eid
+                    self.rqlexec(rql, substs)
 
     def _synchronize_rdef_schema(self, subjtype, rtype, objtype,
                                  syncperms=True, syncprops=True):