Ashroot: Tables That Keep Their Relationships
Design problem and decision
A cinema needs a program in start-time order and every screening needs a room. Decide which stored facts the cinema owns, which queries deserve an index, and what should happen when a room is removed.
The film follows one illustrative cinema on the Internet Computer. The component is the optional Rust Ashroot layer in RSX. The separate Motoko Ashroot tool has its own authoring flow.
Worked design
| Room ID | Name |
|---|---|
| 10 | Studio |
| 20 | Main |
| Screening ID | Film | Day | Start | Room |
|---|---|---|---|---|
| 41 | Lanterns | Sat | 18:00 | 10 |
| 42 | Low Tide | Sat | 19:30 | 20 |
| 43 | Paper Moon | Sat | 22:00 | 10 |
The primary ID identifies one row within its table. The program uses the ordered by_start index on (day, start). Its entries store the projected key and screening ID. The room_id reference targets the Rooms table in the same database and uses Restrict on deletion. For the final edits, screening 41 moves to 20:45, then screenings 41 and 43 are reassigned to room 20. Rescheduling and room capacity rules are decisions the cinema service would own.
Views
Use the light paper canvas and canonical actor boundary, module capsule, call pills, grouped tables and outcome card. Keep the same tables during every close view. Green outlines mark a valid write or match. Red marks an expected refusal while the stored tables hold.
Scene ashroot_ownership — The cinema owns its program
Beat program — Start with what the cinema needs
View and focus The empty place for Saturday's program fills with three screening times. Room names enter on the same rows.
Narration
A cinema publishes its Saturday program in start time order. Every screening needs a room that exists. The cinema owns both facts. It can keep both tables in one actor, next to the code that changes the program.
Cue and animation On “Saturday program”, show three screening times. On “room that exists”, reveal room names. On “one actor”, open the cinema boundary and move the program to the right to make space for its owner.
Leaves with One cinema actor and the program it needs to answer.
Beat tables — One owner for the data
View and focus The cinema actor contains its Scheduling module, and Ashroot shows the rows from the attached private database.
Narration
Ashroot is an optional layer for these tables. Each room and screening has a primary ID. A screening stores its room ID. The cinema's scheduling service asks Ashroot to write each change. Ashroot owns the stored rows and their indexes.
Cue and animation On “optional layer”, reveal the Ashroot database inside the actor. On “primary ID”, highlight both ID columns. On “room ID”, draw the links to Rooms. On “scheduling service”, pulse the service that calls the database.
Leaves with Two related tables and a single write path.
Scene ashroot_index — An index answers a question
Beat read_index — Follow the first two matches
View and focus Keep Screenings by primary ID at left, the ordered index in the middle, and the published program at right.
Narration
The program asks which screenings are on Saturday, earliest first. Give it an ordered index by day and start time. Each entry pairs that key with a screening ID. The query takes the first two matches and follows their IDs to the film names. The cinema chooses the page size and a limit on how many rows the query may visit.
Cue and animation On “ordered index”, project the ordered entries from Screenings. On “first two matches”, highlight entries 41 and 42 and their mapped titles. On “limit on how many rows”, hold the remaining match outside the page.
Leaves with Two delivered results and one entry left for the next page.
Beat reschedule — Update the row and its index together
View and focus Same cinema and index, with the row and moved entry enlarged together.
Narration
Now Lanterns moves to a later time. The service replaces screening forty one under the same ID. Ashroot removes its old index entry and writes the new one. When the program reads again, Low Tide comes first.
Cue and animation On “later time”, show the incoming reschedule request. On “new one”, switch row 41 to 20:45 and move its index entry below 42. On “Low Tide comes first”, refresh the page.
Leaves with Screenings ordered by ID and the secondary view ordered by its newly stored times.
Scene ashroot_relationship — Keep the reference valid
Beat missing_room — Inserting a screening needs a real room
View and focus Room 99 appears as a candidate ID on an incoming screening request. The room table and screening index stay visible.
Narration
Try to add a screening in room ninety nine. The schema declares which table the room reference points to. Ashroot checks that the room exists before it writes. Room ninety nine is missing. The new screening is refused and the program stays as it was.
Cue and animation On “room ninety nine”, bring schedule(44, 99) to Scheduling. On “checks that the room exists”, show the lookup arrive at Rooms. On “new screening is refused”, show Room 99 missing. Keep every saved row and index entry stationary.
Leaves with The refused call and the same persisted program.
Beat restrict_delete — Used rooms cannot be removed
View and focus Show the two incoming references to Studio, room 10, next to the removal request.
Narration
The rule also works from the room side. If the cinema asks to remove Studio, the restrict policy tells Ashroot to refuse while any screening points to it. Lanterns and Paper Moon still do.
Cue and animation On “remove Studio”, show remove_room(10). On “refuse”, return Room still in use. On “Lanterns and Paper Moon”, brighten the two links into Studio.
Leaves with Studio still attached to both screenings.
Beat reassign — Change the program deliberately
View and focus Same database. Scheduling issues two local edits before it retries room removal.
Narration
The cinema can move both screenings to Main first. Their room references now point to room twenty. Studio has no incoming references, so the same removal can succeed. Those are three deliberate edits the cinema chooses to make.
Cue and animation On “move both screenings”, animate the two room IDs and links changing to 20. On “removal can succeed”, remove row 10 and return Room removed. The program still has the same three screenings, now all in Main.
Leaves with A valid program with one room and three screenings.
Scene ashroot_brief — Specify an integrity rule
Beat domain — Scope the promise
View and focus Show the same cinema boundary. A neighboring actor appears only after the limits are clear.
Narration
Foreign keys keep the two tables consistent inside this database. The cinema service still decides who may edit a screening and whether two bookings overlap. If room availability belongs to a different actor, the cinema needs a message and a workflow for that agreement.
Cue and animation On “inside this database”, highlight the owner boundary. On “who may edit”, highlight the service. On “different actor”, reveal the neighboring venue actor and draw a dashed message path.
Leaves with The local integrity boundary and a separate asynchronous agreement.
Beat handoff — What to hand to the team
View and focus Keep the cinema small on the right and reveal a brief beside the versioned memory file tree.
Narration
Give your team the rows the owner keeps, the queries it must answer, and a rule for each relationship. Put those declarations in the owner's memory version. When the schema changes, plan the migration and rehearse it on populated data. Include the allowed edits and the refusals in the test cases.
Cue and animation On “rows the owner keeps”, fill the tables card. On “queries it must answer”, fill the ordered index requirement. On “rule for each relationship”, fill Screenings → Rooms · Restrict. On “owner's memory version”, highlight scheduling/memory/v1.rs. On “rehearse it on populated data”, reveal v2.rs and the test list.
Leaves with A brief with the data, query, and integrity decisions. The migration is designed against a populated predecessor.
Source notes
Rust behavior was checked against RSX at f6c863661. The cinema is a teaching scenario built around behaviors exercised in the SDK fixtures.
- Rust Ashroot overview
- Rust Ashroot authoring guide for ownership, ordered indexes, row replacement, borrowed reads, and the local foreign-key boundary.
- Rust Ashroot conventions for schema placement, expected refusals and upgrade rules.
- Native table checks for restriction before mutation and the upgrade probe for checked reindexing and versioned schema examples.
- Motoko Ashroot at 4f38466 uses its own embedded runtime and source generator.