Skip to content

Purchase orders with suppliers, products and lines

Suppliers, products, purchase orders and lines related by foreign keys and grouped by per.

related volume small PurchasingSuppliersProductsRelationships
Languages
eng
Formats
tsv

Recipe

recipe.gbddl
gbddl 1
language eng

table suppliers rows 6 (
  id      int64 autoincrement primarykey
  name    text company()
  country text country()
)

table products rows 10 (
  id    int64 autoincrement primarykey
  name  text words(maxWords: 3)
  price decimal(8, 2) decimal(min: 1, max: 500)
)

table purchase_orders rows 12 per(suppliers, 1, 3) (
  id          int64 autoincrement primarykey
  supplier_id int64 fk(suppliers.id)
  ordered_on  date date(min: "2023-01-01", max: "2024-12-31")
  status      text enum(values: ["draft", "sent", "confirmed", "received"])
)

table purchase_order_lines rows 30 per(purchase_orders, 1, 4) (
  id         int64 autoincrement primarykey
  order_id   int64 fk(purchase_orders.id)
  product_id int64 fk(products.id)
  quantity   int64 integer(min: 1, max: 20)
  unit_price decimal(8, 2) eq(product_id.price)
)

output tsv (header: false, eol: crlf, bom: true, maxRowsPerFile: 6)

This is the exact recipe.gbddl committed to the repository. Copy it, or download the raw source.

About this recipe

Purchase orders

A multi-table recipe that generates purchase orders: suppliers, products, orders and lines, related by foreign keys and grouped by per.

What it demonstrates

  • Relationships — purchase_orders references suppliers; the lines reference both purchase_orders and products.
  • Row distribution — per(...) groups child rows by parent: each supplier has 1 to 3 orders and each order 1 to 4 lines.
  • Cross-table values — unit_price copies the referenced product's price with eq(product_id.price).
  • TSV output — the recipe writes tab-separated files, one per table.

Run it

Submit the recipe body to POST /api/v1/jobs?input_format=gbddl, or paste it into Chef, to generate the data. The repository's local runner (run by task test) also generates it and verifies its output.

The recipe outputs TSV files: suppliers.tsv, products.tsv, purchase_orders.tsv and purchase_order_lines.tsv.

Guarantees

Every primary key is unique, every foreign key names an existing parent row, per(...) grouping holds, and unit_price equals its product's price. Values are synthetic.

Tested features

Smart types, physical types, rules and formats this recipe exercises and verifies.

companycountrywordsdecimaldateenumintegereqfkperautoincrementprimary-keytsv.headertsv.eoltsv.bomtsv.maxRowsPerFile