# HG changeset patch # User Julien Cristau # Date 1431723954 -7200 # Node ID de5be53e2ea8c65622ee4bafe02d6b653d4b0315 # Parent d309c020d9fb2fdb9e6b535b90b8e89608764609 [migration] add sql constraints on upgrade Related to #5154406. diff -r d309c020d9fb -r de5be53e2ea8 misc/migration/3.21.0_Any.py --- a/misc/migration/3.21.0_Any.py Sun Mar 22 19:10:13 2015 +0100 +++ b/misc/migration/3.21.0_Any.py Fri May 15 23:05:54 2015 +0200 @@ -21,3 +21,16 @@ sync_schema_props_perms('CWEType') sync_schema_props_perms('cwuri') + +from cubicweb.server.schema2sql import check_constraint + +for cwconstraint in rql('Any C WHERE R constrained_by C').entities(): + cwrdef = cwconstraint.reverse_constrained_by[0] + rdef = cwrdef.yams_schema() + cstr = rdef.constraint_by_eid(cwconstraint.eid) + if cstr.type() not in ('BoundaryConstraint', 'IntervalBoundConstraint', 'StaticVocabularyConstraint'): + continue + cstrname, check = check_constraint(rdef.subject, rdef.object, rdef.rtype.type, + cstr, helper, prefix='cw_') + sql('ALTER TABLE %s%s ADD CONSTRAINT %s CHECK(%s)' % ('cw_', rdef.subject.type, cstrname, check)) +commit()