# HG changeset patch # User Julien Cristau # Date 1397055538 -7200 # Node ID 57a16bef82c0adff3663e29f27bece608a02d91b # Parent 74b793086067607c9d47bdcce4055635f8700929 [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 diff -r 74b793086067 -r 57a16bef82c0 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()