Skip to content

DSM — Samples

These are the samples for the DSM — Data Storage Model guide. See also Short info and the tutorial.

Describe Reservations with id, flight_id and seat_count. Require seat_count > 0 and a valid referenced Flight.

  1. Review a row requesting 1 seat on an existing flight: both checks are satisfied.
  2. Review a row requesting 0 seats: the positive-count check should reject it.
  3. Review a row referencing a missing flight: the foreign key should reject it.
  4. Ask whether these checks prevent two valid rows from collectively exceeding capacity.

They do not establish that broader guarantee. Link the capacity obligation to DDD/CBRL and choose a transaction strategy with tests for competing requests.

For a concrete model file, download the travel-booking checkpoint and follow the travel-booking tutorial. The checkpoint is cumulative and may contain earlier model stages.

These four exercises are lesson briefs. Their dedicated CtxBazaar recipes and browser launch actions are planned; see Learning with models for available downloads and the meaning of each result.

Exercise Try this Expected observation
One constrained table Describe a reservations table with an identifier and a positive seat-count constraint. Distinguish a valid row from a zero-seat row that the intended database constraint rejects.
Parent and child Link reservations to flights using a foreign key. Identify the missing-parent case and the intended integrity check.
Index for a query Add a route/date index to support flight search. Explain the target query and the index’s write/storage cost; no latency claim is made without measurement.
Schema change review Compare a nullable contact field with a proposed required field. Identify existing rows that need a backfill before enforcing the new constraint.
Artifact Description
Schema validation tests Verify constraints are enforced at the DB level
Migration safety tests Check migrations are reversible and non-destructive
Drizzle ORM schema TypeScript Drizzle table definitions
TypeScript types Interfaces matching table structures
Migration files Up/down SQL migration scripts
describe("books table constraints", () => {
it("rejects duplicate ISBN", async () => {
await insertBook({ isbn: "978-0-13-468599-1" });
await expect(insertBook({ isbn: "978-0-13-468599-1" })).rejects.toThrow(
/unique.*isbn/i,
);
});
it("rejects ISBN with invalid length", async () => {
await expect(insertBook({ isbn: "123" })).rejects.toThrow(
/valid_isbn_length/,
);
});
});