{
 "$schema": "../../lib/umlimator.schema.json",
 "schemaVersion": 2,
 "title": "Entity-relationship diagram",
 "root": "schema",
 "nodes": [
  { "id": "customer", "type": "er.Entity", "label": "customer",
   "members": [
    { "id": "customer.id", "type": "er.Column", "label": "id", "props": { "dataType": "bigint", "primaryKey": true } },
    { "id": "customer.email", "type": "er.Column", "label": "email", "props": { "dataType": "varchar(255)", "unique": true } },
    { "id": "customer.name", "type": "er.Column", "label": "name", "props": { "dataType": "varchar(120)" } },
    { "id": "customer.referred_by", "type": "er.Column", "label": "referred_by", "props": { "dataType": "bigint", "foreignKey": true, "nullable": true, "references": "customer.id" } },
    { "id": "customer.phone", "type": "er.Column", "label": "phone", "props": { "dataType": "varchar(20)", "nullable": true } },
    { "id": "customer.created_at", "type": "er.Column", "label": "created_at", "props": { "dataType": "timestamptz" } }
   ] },
  { "id": "order", "type": "er.Entity", "label": "order",
   "members": [
    { "id": "order.id", "type": "er.Column", "label": "id", "props": { "dataType": "bigint", "primaryKey": true } },
    { "id": "order.customer_id", "type": "er.Column", "label": "customer_id", "props": { "dataType": "bigint", "foreignKey": true, "references": "customer.id" } },
    { "id": "order.status", "type": "er.Column", "label": "status", "props": { "dataType": "varchar(12)" } },
    { "id": "order.placed_at", "type": "er.Column", "label": "placed_at", "props": { "dataType": "timestamptz", "nullable": true } }
   ] },
  { "id": "order_line", "type": "er.Entity", "label": "order_line",
   "members": [
    { "id": "order_line.order_id", "type": "er.Column", "label": "order_id", "props": { "dataType": "bigint", "primaryKey": true, "foreignKey": true, "references": "order.id" } },
    { "id": "order_line.line_no", "type": "er.Column", "label": "line_no", "props": { "dataType": "integer", "primaryKey": true } },
    { "id": "order_line.book_id", "type": "er.Column", "label": "book_id", "props": { "dataType": "bigint", "foreignKey": true, "references": "book.id" } },
    { "id": "order_line.quantity", "type": "er.Column", "label": "quantity", "props": { "dataType": "integer" } },
    { "id": "order_line.unit_price", "type": "er.Column", "label": "unit_price", "props": { "dataType": "numeric(10,2)" } }
   ] },
  { "id": "book", "type": "er.Entity", "label": "book",
   "members": [
    { "id": "book.id", "type": "er.Column", "label": "id", "props": { "dataType": "bigint", "primaryKey": true } },
    { "id": "book.isbn", "type": "er.Column", "label": "isbn", "props": { "dataType": "char(13)", "unique": true } },
    { "id": "book.title", "type": "er.Column", "label": "title", "props": { "dataType": "varchar(255)" } },
    { "id": "book.price", "type": "er.Column", "label": "price", "props": { "dataType": "numeric(10,2)" } }
   ] },
  { "id": "author", "type": "er.Entity", "label": "author",
   "members": [
    { "id": "author.id", "type": "er.Column", "label": "id", "props": { "dataType": "bigint", "primaryKey": true } },
    { "id": "author.name", "type": "er.Column", "label": "name", "props": { "dataType": "varchar(120)" } }
   ] },
  { "id": "book_author", "type": "er.Entity", "label": "book_author",
   "members": [
    { "id": "book_author.book_id", "type": "er.Column", "label": "book_id", "props": { "dataType": "bigint", "primaryKey": true, "foreignKey": true, "references": "book.id" } },
    { "id": "book_author.author_id", "type": "er.Column", "label": "author_id", "props": { "dataType": "bigint", "primaryKey": true, "foreignKey": true, "references": "author.id" } }
   ] },
  { "id": "payment", "type": "er.Entity", "label": "payment",
   "members": [
    { "id": "payment.id", "type": "er.Column", "label": "id", "props": { "dataType": "bigint", "primaryKey": true } },
    { "id": "payment.order_id", "type": "er.Column", "label": "order_id", "props": { "dataType": "bigint", "foreignKey": true, "unique": true, "references": "order.id" } },
    { "id": "payment.amount", "type": "er.Column", "label": "amount", "props": { "dataType": "numeric(10,2)" } }
   ] },
  { "id": "note-lines", "type": "uml.Comment", "label": "an order_line is keyed by its order and its number in it" }
 ],
 "edges": [
  { "id": "customer-orders", "type": "er.Relationship", "from": "customer", "to": "order", "label": "places",
   "props": { "identifying": false, "ends": { "from": { "multiplicity": "1" }, "to": { "multiplicity": "0..*" } } } },
  { "id": "order-lines", "type": "er.Relationship", "from": "order", "to": "order_line", "label": "contains",
   "props": { "identifying": true, "ends": { "from": { "multiplicity": "1" }, "to": { "multiplicity": "1..*" } } } },
  { "id": "book-lines", "type": "er.Relationship", "from": "book", "to": "order_line", "label": "sold as",
   "props": { "identifying": false, "ends": { "from": { "multiplicity": "1" }, "to": { "multiplicity": "0..*" } } } },
  { "id": "book-authors", "type": "er.Relationship", "from": "book", "to": "book_author",
   "props": { "identifying": true, "ends": { "from": { "multiplicity": "1" }, "to": { "multiplicity": "1..*" } } } },
  { "id": "author-books", "type": "er.Relationship", "from": "author", "to": "book_author",
   "props": { "identifying": true, "ends": { "from": { "multiplicity": "1" }, "to": { "multiplicity": "0..*" } } } },
  { "id": "order-payment", "type": "er.Relationship", "from": "order", "to": "payment", "label": "paid by",
   "props": { "identifying": false, "ends": { "from": { "multiplicity": "1" }, "to": { "multiplicity": "0..1" } } } },
  { "id": "customer-referrals", "type": "er.Relationship", "from": "customer", "to": "customer", "label": "referred",
   "props": { "identifying": false, "ends": { "from": { "multiplicity": "0..1" }, "to": { "multiplicity": "0..*" } } } },
  { "id": "note-lines-link", "type": "uml.CommentLink", "from": "note-lines", "to": "order_line" }
 ],
 "views": [
  { "id": "schema", "diagram": "er", "title": "A bookshop's database", "parent": null, "notation": "crowsfoot", "layout": { "note-lines": [3, 2] },
   "nodeIds": ["customer", "order", "order_line", "book", "author", "book_author", "payment", "note-lines"],
   "present": { "customer": { "rows": 3 }, "book": { "collapsed": ["columns"] } } },
  { "id": "schema-idef1x", "diagram": "er", "title": "The same database in IDEF1X", "parent": "schema", "notation": "idef1x", "layout": { "note-lines": [3, 2] },
   "nodeIds": ["customer", "order", "order_line", "book", "author", "book_author", "payment", "note-lines"],
   "present": { "customer": { "rows": 3 }, "book": { "collapsed": ["columns"] } } }
 ]
}
