Constraints
At some point, you will want to generate data that is representative of the real world. For example, you may want to ensure that the CreatedAt field is always less than the ModifiedAt field. This is where constraints come in.
There are a number of constraints that can be applied to fields, NOT ALL FIELD TYPES SUPPORT ALL CONSTRAINTS.
At present, the following constraints are available:
Usage
Constraints are applied directly to fields in the schema. The field that they are defined on is the field that the constraint will be applied to.
GreaterThan
The GreaterThan constraint ensures that the value of the field is greater than the value of another field.
The following will result in the B field being greater than the A field.
fields:
- name: A
type: Digit
- name: B
type: Digit
constraints:
- type: GreaterThan
name: A
IfNull
The IfNull constraint ensures that the value of the field is only generated if the value of another field is null. This has the effect of making two fields mutually exclusive.
The following will result in the B field being generated if the A field is null which should result in each field being generated 50% of the time.
fields:
- name: A
type: Digit
null_probability: 0.5
- name: B
type: Digit
constraints:
- type: IfNull
name: A