[schema, old instance] restore some pre 3.5.10 bw compat as some old instances may still have this, and add migration so we can remove it at some point
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 27 Oct 2011 10:38:02 +0200
changeset 8027 9ac82788f67b
parent 8026 98222e3bb804
child 8028 58e9bc8a1f2c
[schema, old instance] restore some pre 3.5.10 bw compat as some old instances may still have this, and add migration so we can remove it at some point
misc/migration/3.14.0_Any.py
schema.py
--- a/misc/migration/3.14.0_Any.py	Wed Oct 26 17:59:06 2011 +0200
+++ b/misc/migration/3.14.0_Any.py	Thu Oct 27 10:38:02 2011 +0200
@@ -1,3 +1,13 @@
 config['rql-cache-size'] = config['rql-cache-size'] * 10
 
 add_entity_type('CWDataImport')
+
+from cubicweb.schema import CONSTRAINTS, guess_rrqlexpr_mainvars
+for rqlcstr in rql('Any X,XT,XV WHERE X is CWConstraint, X cstrtype XT, X value XV,'
+                   'X cstrtype XT, XT name IN ("RQLUniqueConstraint","RQLConstraint","RQLVocabularyConstraint"),'
+                   'NOT X value ~= ";%"').entities():
+    expression = rqlcstr.value
+    mainvars = guess_rrqlexpr_mainvars(expression)
+    yamscstr = CONSTRAINTS[rqlcstr.type](expression, mainvars)
+    rqlcstr.set_attributes(value=yamscstr.serialize())
+    print 'updated', rqlcstr.type, rqlcstr.value
--- a/schema.py	Wed Oct 26 17:59:06 2011 +0200
+++ b/schema.py	Thu Oct 27 10:38:02 2011 +0200
@@ -929,6 +929,9 @@
 
     @classmethod
     def deserialize(cls, value):
+        # XXX < 3.5.10 bw compat
+        if not value.startswith(';'):
+            return cls(value)
         _, mainvars, expression = value.split(';', 2)
         return cls(expression, mainvars)
 
@@ -983,6 +986,9 @@
                                self.msg or '')
 
     def deserialize(cls, value):
+        # XXX < 3.5.10 bw compat
+        if not value.startswith(';'):
+            return cls(value)
         value, msg = value.split('\n', 1)
         _, mainvars, expression = value.split(';', 2)
         return cls(expression, mainvars, msg)