Constraints for property values (min, max, regex...)
Proposal
Constraints for Abstract Properties
When constraints are defined for an Abstract Property like this
import caosdb as db
db.Property("age", datatype=db.INTEGER, constraints={"min": 0}, description="Age in Years. Must not be negative")
... then he constraints are being "inherited" be any RecordType Property and the constraints are being enforced when the Property is added to a Record or File entity.
Constraints for RecordType Properties
When a RecordType Property has constraints like this
import caosdb as db
db.Property("stick measure", datatype=db.Integer, unit="cm", description="Stick measure of a horse")
db.RecordType("Pony").add_property("stick measure", constraints={"max", "148cm"})
... then the constraints are being enforced when the property is being added to a Record or File entity.
Enforcement of Constraints
- When the property value does not comply with the contraints, e.g. when a "Pony" Record has a "stick measure" of "149cm" then a warning or an error is being thrown.
- Default is error.
- Enforcement can be overridden with
--ignore-value-constraints
flag for a particular Concrete Property pr the whole Record/File - Constraints can be reduced to warning level via
constraints={"max": { "recommended": "100Y", "obligatory": "130Y" }}
.
Types of Constraints
- min/max for numerical values and dates.
- regex patterns for string, e.g
{"regex": "[^\s]"}
which means no empty space. - See JSON-Schema for more