SQL
Reject impossible maintenance jobs
P99 was registered, but J1 lost its duration
An otherwise readable inspection job points to an absent pump. Protect the relationship and its duration rule together.
BOTIE
The inputs we are comparing
Proposed jobs
One job points to an absent pump
[
{
"id": "J1",
"asset_id": "P7",
"minutes": 20
},
{
"id": "J2",
"asset_id": "P99",
"minutes": 10
}
]The parent is added but duration is missing
[
{
"id": "J1",
"asset_id": "P7",
"minutes": null
},
{
"id": "J2",
"asset_id": "P99",
"minutes": 10
}
]Registered asset IDs
One job points to an absent pump
- 0P7
- 1P8
The parent is added but duration is missing
- 0P7
- 1P99
Result for one job points to an absent pump
- 0J2
The asset exists but the duration is negative
This check uses the pieces from “Check each job against its parent and duration”.
BOTIE
- Proposed jobs
[ { "id": "J7", "asset_id": "P2", "minutes": -5 }, { "id": "J8", "asset_id": "P2", "minutes": 12 } ]- Registered asset IDs
- 0P2
Use a number, text, or an array matching the requested result. For a matrix, put each row in brackets. Saving your prediction runs your current construction on these inputs and checks the earlier examples too.
Build a construction in the workspace above first. This case will test those pieces.
Why does a foreign key not establish which technician is allowed to see the asset?
Separate data validity from authorisation, and test both at their proper boundaries.
The widget illustrates selected invariants. The SQL table additionally enforces uniqueness and database-level relationships.
Work through the SQL challenges →