Published public, drafts private
Readers see published posts; authors also see their drafts.- Any of these rules pass:
- Compare values:
$record.statusequalspublished - Owns the record (field)
author_id
- Compare values:
list and get. (Per-row, so totals can be null; see evaluation.)
Hide deleted records
With a nullabledeleted_at column (soft delete):
- All of these rules pass:
- Owns the record (field)
owner_id - Check a value:
$record.deleted_atis empty
- Owns the record (field)
Scheduled publishing
Visible oncepublish_at has passed:
- Any of these rules pass:
- Check a value:
$record.publish_atis empty - Compare values:
$record.publish_atis at most$now
- Check a value:
publish_at means “publish immediately”. Without the empty branch, those rows would never be visible (lte with a missing side is false).
Expiring content
- Any of these rules pass:
- Check a value:
$record.expires_atis empty - Compare values:
$record.expires_atis greater than$now
- Check a value:
Locked records
No edits once locked:- All of these rules pass:
- Owns the record (field)
owner_id - Compare values:
$record.lockeddoes not equal yes
- Owns the record (field)
update and delete. A rule can’t unlock; do that from a service or a role: { "any": [{ "role": "admin" }, <the rule above>] }.
Only forward state changes
Let the owner move a record fromdraft to submitted, but not edit approved ones:
- All of these rules pass:
- Owns the record (field)
owner_id - Compare values:
$record.statusis one ofdraft, submitted - Compare values:
$input.statusis one ofdraft, submitted
- Owns the record (field)
update. Approval is a separate step done by role:reviewer through another route.
Limit values
- All of these rules pass:
- Is signed in: yes
- Compare values:
$input.quantityis at most10 - Compare values:
$input.quantityis at least1
create. For hard limits that must hold however the record is written, also set the column’s minimum/maximum (Columns).
Rate-limited by state
“At most 3 open orders” can’t be a rule built in Studio: it needs a count of other rows. Do it in a route, or a unique partial index, such as one open cart per customer.Honour the visibility of related records
A comment is visible if its post is. Comments can’t look at the post in a rule built in Studio. Either copy the post’svisibility onto the comment on create, or give comments the rule public and only expose them through the post with expand, which reads comments under the comments table’s rule.
Patterns
Database designs.
Values and paths
Missing-value pitfalls.