misc/migration/bootstrapmigration_repository.py
changeset 10015 57a16bef82c0
parent 9708 b36bc18f6ef7
child 10025 7b72ecc3f4d2
--- a/misc/migration/bootstrapmigration_repository.py	Mon Jul 07 16:07:57 2014 +0200
+++ b/misc/migration/bootstrapmigration_repository.py	Wed Apr 09 16:58:58 2014 +0200
@@ -254,3 +254,18 @@
 
 if applcubicwebversion < (3, 2, 0) and cubicwebversion >= (3, 2, 0):
     add_cube('card', update_database=False)
+
+def sync_constraint_types():
+    """Make sure the repository knows about all constraint types defined in the code"""
+    from cubicweb.schema import CONSTRAINTS
+    repo_constraints = set(row[0] for row in rql('Any N WHERE X is CWConstraintType, X name N'))
+
+    for cstrtype in set(CONSTRAINTS) - repo_constraints:
+        if cstrtype == 'BoundConstraint':
+            # was renamed to BoundaryConstraint, we don't need the old name
+            continue
+        rql('INSERT CWConstraintType X: X name %(name)s', {'name': cstrtype})
+
+    commit()
+
+sync_constraint_types()