What it is
Referential integrity for SpacetimeDB tables. Declare once how your tables reference each other, and checked writes refuse rows that point nowhere. Deletes then cascade, set the reference to null, or are refused (restrict), all or nothing.
Before deleting, you can ask what would happen: "this also deletes 3 lists, 12 cards and 30 comments, and unassigns 2 cards". It also adds multi-column unique constraints, a check and repair pass for orphans left behind by older code, and pagination as keyset cursors or live per-client pages.
Where it fits
- Any module with parent/child data where a dangling reference is a bug: boards, lists and cards; guilds and members; orders and line items; posts and comments.
- It's especially useful for deletes, where the alternative is hand-written cleanup code in every reducer that removes something.
How it works
Register your tables with relations.table({...}), which hands back a checked handle, and declare rules with relations.reference({ child, column, parent, onDelete }) and relations.unique({...}).
Inserts, updates and deletes made through the handles enforce the rules inside the same transaction. A violation throws and rolls everything back.
previewDelete returns the full delete plan without changing anything. The relationsCheck / relationsRepair procedures find and fix what slipped through raw writes. The client-facing names match the Rust and C# versions.


