Ashroot: Tables That Keep Their Relationships
Chapters
- The cinema owns its program
- An index answers a question
- Keep the reference valid
- Specify an integrity rule
Transcript
The cinema owns its program
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. 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.
An index answers a question
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. 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.
Keep the reference valid
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. 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. 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.
Specify an integrity rule
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. 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.