{
 "name": "shop",
 "label": "Illustrative demo",
 "engine": "fabric_backend.infer.plan",
 "keys_given": {
  "order_items": [
   "order_id",
   "line_no"
  ]
 },
 "summary": "7 tables, 6 with keys, 6 relationships\nno key (query only; can reference others, cannot be referenced): audit_log",
 "rules": {
  "K0": "declared primary key",
  "K1": "`keys` override from the caller",
  "K2": "a column named `id`, `<table>_id`, `<table>id`, `<singular>_id`, `<singular>id`, `<table>_key`, `<table>_code`, `<table>_nr`, `<table>_no`, or an abbreviation of the table name (four letters or more) with one of those suffixes",
  "K3": "nothing \u2014 the table gets no key; it can be queried but not by pk, and nothing can point at it",
  "K4": "junction: no column names a key and the table starts with two or more reference columns; together they are the key (not applied to history tables with a start_*/valid_from/effective_* column)",
  "K5": "line: no column names a key; the reference to the header table plus a line-number column (line_no, position, seq\u2026)",
  "R0": "declared foreign key",
  "R1": "column named `<B>_id` / `<B>id` / `<singular B>_id` / `<singular B>id` (also _key, _code, _nr, _no) where B has a single key",
  "R2": "column has exactly the same name as B's single key column, and that name is not just `id`",
  "R3": "all of B's composite key columns appear in A",
  "R4": "weaker name match when R1 and R2 find nothing: a role before B's name (`manager_staff_id` \u2192 staff) or an abbreviation of B of four letters or more (`o_custkey` \u2192 customer)",
  "confirmed": "given by the caller in `confirmed=[...]`, applied as-is, before inference"
 },
 "tables": [
  {
   "name": "customers",
   "columns": [
    {
     "name": "customer_id",
     "type": "int",
     "key": true,
     "linked": true
    },
    {
     "name": "name",
     "type": "string",
     "key": false,
     "linked": false
    },
    {
     "name": "country",
     "type": "string",
     "key": false,
     "linked": false
    }
   ],
   "key": [
    "customer_id"
   ],
   "key_rule": "K2",
   "rows": 10
  },
  {
   "name": "categories",
   "columns": [
    {
     "name": "id",
     "type": "int",
     "key": true,
     "linked": true
    },
    {
     "name": "name",
     "type": "string",
     "key": false,
     "linked": false
    }
   ],
   "key": [
    "id"
   ],
   "key_rule": "K2",
   "rows": 3
  },
  {
   "name": "products",
   "columns": [
    {
     "name": "product_id",
     "type": "int",
     "key": true,
     "linked": true
    },
    {
     "name": "name",
     "type": "string",
     "key": false,
     "linked": false
    },
    {
     "name": "category_id",
     "type": "int",
     "key": false,
     "linked": true
    }
   ],
   "key": [
    "product_id"
   ],
   "key_rule": "K2",
   "rows": 8
  },
  {
   "name": "addresses",
   "columns": [
    {
     "name": "address_id",
     "type": "int",
     "key": true,
     "linked": false
    },
    {
     "name": "customer_id",
     "type": "int",
     "key": false,
     "linked": true
    },
    {
     "name": "city",
     "type": "string",
     "key": false,
     "linked": false
    }
   ],
   "key": [
    "address_id"
   ],
   "key_rule": "K2",
   "rows": 17
  },
  {
   "name": "orders",
   "columns": [
    {
     "name": "order_id",
     "type": "int",
     "key": true,
     "linked": true
    },
    {
     "name": "customer_id",
     "type": "int",
     "key": false,
     "linked": true
    },
    {
     "name": "order_date",
     "type": "date",
     "key": false,
     "linked": false
    },
    {
     "name": "ship_to_id",
     "type": "int",
     "key": false,
     "linked": false
    }
   ],
   "key": [
    "order_id"
   ],
   "key_rule": "K2",
   "rows": 60
  },
  {
   "name": "order_items",
   "columns": [
    {
     "name": "order_id",
     "type": "int",
     "key": true,
     "linked": true
    },
    {
     "name": "line_no",
     "type": "int",
     "key": true,
     "linked": false
    },
    {
     "name": "product_id",
     "type": "int",
     "key": false,
     "linked": true
    },
    {
     "name": "quantity",
     "type": "double",
     "key": false,
     "linked": false
    }
   ],
   "key": [
    "order_id",
    "line_no"
   ],
   "key_rule": "K1",
   "rows": 134
  },
  {
   "name": "audit_log",
   "columns": [
    {
     "name": "event",
     "type": "string",
     "key": false,
     "linked": false
    },
    {
     "name": "customer_id",
     "type": "int",
     "key": false,
     "linked": true
    },
    {
     "name": "happened_at",
     "type": "timestamp",
     "key": false,
     "linked": false
    }
   ],
   "key": [],
   "key_rule": "K3",
   "rows": 40
  }
 ],
 "relationships": [
  {
   "source": "products",
   "source_cols": [
    "category_id"
   ],
   "target": "categories",
   "target_cols": [
    "id"
   ],
   "rule": "R1",
   "field": "category",
   "reverse": "products"
  },
  {
   "source": "addresses",
   "source_cols": [
    "customer_id"
   ],
   "target": "customers",
   "target_cols": [
    "customer_id"
   ],
   "rule": "R1",
   "field": "customer",
   "reverse": "addresses"
  },
  {
   "source": "orders",
   "source_cols": [
    "customer_id"
   ],
   "target": "customers",
   "target_cols": [
    "customer_id"
   ],
   "rule": "R1",
   "field": "customer",
   "reverse": "orders"
  },
  {
   "source": "order_items",
   "source_cols": [
    "order_id"
   ],
   "target": "orders",
   "target_cols": [
    "order_id"
   ],
   "rule": "R1",
   "field": "order",
   "reverse": "order_items"
  },
  {
   "source": "order_items",
   "source_cols": [
    "product_id"
   ],
   "target": "products",
   "target_cols": [
    "product_id"
   ],
   "rule": "R1",
   "field": "product",
   "reverse": "order_items"
  },
  {
   "source": "audit_log",
   "source_cols": [
    "customer_id"
   ],
   "target": "customers",
   "target_cols": [
    "customer_id"
   ],
   "rule": "R1",
   "field": "customer",
   "reverse": "audit_log"
  }
 ],
 "ambiguous": [],
 "keyless": [
  "audit_log"
 ],
 "unlinked": [
  {
   "table": "orders",
   "column": "ship_to_id",
   "note": "no rule matched: not named after another table, and not another table's key name"
  }
 ],
 "suggestions": [
  {
   "table": "orders",
   "column": "ship_to_id",
   "target": "addresses",
   "target_cols": [
    "address_id"
   ],
   "source": "demo hint, not inferred",
   "why": "the synthetic seed stores address ids in this column"
  }
 ],
 "mermaid": "erDiagram\n  customers {\n    customer_id int PK\n    name string\n    country string\n  }\n  categories {\n    id int PK\n    name string\n  }\n  products {\n    product_id int PK\n    name string\n    category_id int\n  }\n  addresses {\n    address_id int PK\n    customer_id int\n    city string\n  }\n  orders {\n    order_id int PK\n    customer_id int\n    order_date date\n    ship_to_id int\n  }\n  order_items {\n    order_id int PK\n    line_no int PK\n    product_id int\n    quantity double\n  }\n  audit_log {\n    event string\n    customer_id int\n    happened_at timestamp\n  }\n  categories ||--o{ products : \"category_id R1\"\n  customers ||--o{ addresses : \"customer_id R1\"\n  customers ||--o{ orders : \"customer_id R1\"\n  orders ||--o{ order_items : \"order_id R1\"\n  products ||--o{ order_items : \"product_id R1\"\n  customers ||--o{ audit_log : \"customer_id R1\""
}