Skip to content
Jupiter documentation
Menu

Data model

The nine D1 tables, their relationships and how deletes work.

The schema in migrations/0001_init.sql has nine tables. Every id is an INTEGER PRIMARY KEY AUTOINCREMENT.

Tables and relationships#

Uniqueness rules beyond the primary keys:

Review scores carry a CHECK (score BETWEEN 1 AND 5) constraint, so an out-of-range score fails the insert even if a route missed it.

Deletes#

Two kinds of delete exist:

  • Soft delete for recipes, classifications, reviews and menus: the row stays and is_publish becomes 0. List endpoints filter on is_publish = 1; reads by id still find the row.
  • Hard delete for ingredients: the row goes.

Deleting is refused with 400 when other rows depend on the resource: a recipe that appears in a Mapping, or a classification that recipes reference. Customers soft delete through is_active instead of is_publish.

Derived values#

A recipe response carries has_links (true when a mapping references it) and its full ingredient list. A weekly menu response carries recipes (its mappings) and score, the mean of its menu reviews, or 0 with no reviews. Both are computed per request, not stored.

Nutrition#

The 2021 Postgres schema stored nutrition as an hstore. D1 has no hstore, so nutrition is a JSON text column. Routes parse it on read and stringify it on write, so the API keeps accepting and returning a JSON object.

Source: belikh/hello-fresh-API HEAD