24 |
24 |
25 from yams.constraints import (SizeConstraint, UniqueConstraint, Attribute, |
25 from yams.constraints import (SizeConstraint, UniqueConstraint, Attribute, |
26 NOW, TODAY) |
26 NOW, TODAY) |
27 from logilab import database |
27 from logilab import database |
28 from logilab.common.decorators import monkeypatch |
28 from logilab.common.decorators import monkeypatch |
|
29 |
|
30 from cubicweb.schema import constraint_name_for |
29 |
31 |
30 # default are usually not handled at the sql level. If you want them, set |
32 # default are usually not handled at the sql level. If you want them, set |
31 # SET_DEFAULT to True |
33 # SET_DEFAULT to True |
32 SET_DEFAULT = False |
34 SET_DEFAULT = False |
33 |
35 |
185 def check_constraint(rdef, constraint, dbhelper, prefix=''): |
187 def check_constraint(rdef, constraint, dbhelper, prefix=''): |
186 """Return (constraint name, constraint SQL definition) for the given relation definition's |
188 """Return (constraint name, constraint SQL definition) for the given relation definition's |
187 constraint. Maybe (None, None) if the constraint is not handled in the backend. |
189 constraint. Maybe (None, None) if the constraint is not handled in the backend. |
188 """ |
190 """ |
189 attr = rdef.rtype.type |
191 attr = rdef.rtype.type |
190 cstrname = constraint.name_for(rdef) |
192 cstrname = constraint_name_for(constraint, rdef) |
191 if constraint.type() == 'BoundaryConstraint': |
193 if constraint.type() == 'BoundaryConstraint': |
192 value = constraint_value_as_sql(constraint.boundary, dbhelper, prefix) |
194 value = constraint_value_as_sql(constraint.boundary, dbhelper, prefix) |
193 return cstrname, '%s%s %s %s' % (prefix, attr, constraint.operator, value) |
195 return cstrname, '%s%s %s %s' % (prefix, attr, constraint.operator, value) |
194 elif constraint.type() == 'IntervalBoundConstraint': |
196 elif constraint.type() == 'IntervalBoundConstraint': |
195 condition = [] |
197 condition = [] |