[migration] make sure the repo knows about all constraint types
authorJulien Cristau <julien.cristau@logilab.fr>
Wed, 09 Apr 2014 16:58:58 +0200
changeset 10015 57a16bef82c0
parent 10014 74b793086067
child 10016 984505da8b89
[migration] make sure the repo knows about all constraint types Adding new constraint types is cumbersome. It's easy to forget to do it in a migration script. So sync the constraint types at the beginning of each migration. Closes #3724892
misc/migration/bootstrapmigration_repository.py
--- 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()