[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
--- 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()