Skip to content

Organization directory with a self-reference and head-of-organization cycle

Organizations in a self-referencing hierarchy, their heads, and the people who work for them, forming a foreign-key cycle.

related volume small OrganizationPeopleRelationships
Languages
eng
Formats
csv

Recipe

recipe.gbddl
gbddl 1
language eng

table organizations rows 10 (
  id        int64 autoincrement primarykey
  name      text company()
  parent_id int64 null(20%) fk(organizations.id)
  head_id   int64 null(30%) fk(people.id)
)

table people rows 30 per(organizations, 1, 5) (
  id              int64 autoincrement primarykey
  organization_id int64 fk(organizations.id)
  full_name       text same(person) fullName()
  email           text same(person) email()
  role            text enum(values: ["executive", "manager", "staff", "contractor"])
)

output csv

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

About this recipe

Organization directory

A multi-table recipe that generates an organization directory: organizations in a self-referencing hierarchy, their heads, and the people who work for them. The head-of-organization reference and the people-to-organization reference form a foreign-key cycle.

What it demonstrates

  • Self-reference — organizations.parent_id references organizations.id, so each organization may point at a parent in the same table; it is null in 20% of rows (top-level organizations).
  • Foreign-key cycle — organizations.head_id references people.id while people.organization_id references organizations.id, a two-table cycle that closes on nullable keys (the head is null in 30% of rows).
  • Relationships — people references organizations.
  • Row distribution — per(organizations, 1, 5) gives each organization one to five people.

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 CSV files: organizations.csv and people.csv.

Guarantees

Every primary key is unique, every parent_id names an existing organization, and per(...) grouping holds. Values are synthetic.

Tested features

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

companyfullNameemailenumnullself-referencefkfk-cyclepersame:personautoincrementprimary-key