From 4af2fca339735a9343be7b77185c03acf1b58b1e Mon Sep 17 00:00:00 2001 From: Ibrahim Wassouf Date: Thu, 6 Jul 2023 19:40:54 -0300 Subject: [PATCH 1/4] Add documentation for feature --- docs/syntax/entityRelationshipDiagram.md | 2 +- packages/mermaid/src/docs/syntax/entityRelationshipDiagram.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/syntax/entityRelationshipDiagram.md b/docs/syntax/entityRelationshipDiagram.md index 9fa5fa5173..dd887b0ee2 100644 --- a/docs/syntax/entityRelationshipDiagram.md +++ b/docs/syntax/entityRelationshipDiagram.md @@ -196,7 +196,7 @@ erDiagram } ``` -The `type` and `name` values must begin with an alphabetic character and may contain digits, hyphens, underscores, parentheses and square brackets. Other than that, there are no restrictions, and there is no implicit set of valid data types. +The `type` values must begin with an alphabetic character and may contain digits, hyphens, underscores, parentheses and square brackets. The `name` values follow a similar format to `type`, but may start with an asterisk as another option to indicate an attribute is a primary key. Other than that, there are no restrictions, and there is no implicit set of valid data types. #### Attribute Keys and Comments diff --git a/packages/mermaid/src/docs/syntax/entityRelationshipDiagram.md b/packages/mermaid/src/docs/syntax/entityRelationshipDiagram.md index b7066ab3d0..7e5fa2711c 100644 --- a/packages/mermaid/src/docs/syntax/entityRelationshipDiagram.md +++ b/packages/mermaid/src/docs/syntax/entityRelationshipDiagram.md @@ -142,7 +142,7 @@ erDiagram } ``` -The `type` and `name` values must begin with an alphabetic character and may contain digits, hyphens, underscores, parentheses and square brackets. Other than that, there are no restrictions, and there is no implicit set of valid data types. +The `type` values must begin with an alphabetic character and may contain digits, hyphens, underscores, parentheses and square brackets. The `name` values follow a similar format to `type`, but may start with an asterisk as another option to indicate an attribute is a primary key. Other than that, there are no restrictions, and there is no implicit set of valid data types. #### Attribute Keys and Comments From 42da53f58a4b933035325c8762af80b5297fb976 Mon Sep 17 00:00:00 2001 From: Ibrahim Wassouf Date: Thu, 6 Jul 2023 22:15:18 -0300 Subject: [PATCH 2/4] Add imgSnapshotTest --- .../integration/rendering/erDiagram.spec.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cypress/integration/rendering/erDiagram.spec.js b/cypress/integration/rendering/erDiagram.spec.js index 0c6eaa8386..91c93b6a85 100644 --- a/cypress/integration/rendering/erDiagram.spec.js +++ b/cypress/integration/rendering/erDiagram.spec.js @@ -200,6 +200,27 @@ describe('Entity Relationship Diagram', () => { ); }); + it('should render entities with attributes that begin with asterisk', () => { + imgSnapshotTest( + ` + erDiagram + BOOKS { + int *id + string name + varchar(99) summary + } + BOOKS }o..o{ STORES : sold + STORES { + int *id + string name + varchar(50) address + } + `, + { loglevel: 1 } + ); + cy.get('svg'); + }); + it('should render entities with keys', () => { renderGraph( ` From fad11bce9551d6efa5d65696f4e1127245e0bcf8 Mon Sep 17 00:00:00 2001 From: Ibrahim Wassouf Date: Thu, 6 Jul 2023 22:17:33 -0300 Subject: [PATCH 3/4] Correct one unit test and add another --- .../src/diagrams/er/parser/erDiagram.spec.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js b/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js index 4ab09b2f87..2bf2f5b8c8 100644 --- a/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js +++ b/packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js @@ -154,11 +154,21 @@ describe('when parsing ER diagram it...', function () { expect(entities[entity].attributes[2].attributeName).toBe('author-ref[name](1)'); }); - it('should allow asterisk at the start of title', function () { + it('should allow asterisk at the start of attribute name', function () { const entity = 'BOOK'; const attribute = 'string *title'; - erDiagram.parser.parse(`erDiagram\n${entity}{${attribute}}`); + erDiagram.parser.parse(`erDiagram\n${entity}{\n${attribute}}`); + const entities = erDb.getEntities(); + expect(Object.keys(entities).length).toBe(1); + expect(entities[entity].attributes.length).toBe(1); + }); + + it('should allow asterisks at the start of attribute declared with type and name', () => { + const entity = 'BOOK'; + const attribute = 'id *the_Primary_Key'; + + erDiagram.parser.parse(`erDiagram\n${entity} {\n${attribute}}`); const entities = erDb.getEntities(); expect(Object.keys(entities).length).toBe(1); expect(entities[entity].attributes.length).toBe(1); From cd118ad5cbb402aff7703fa7b78301fd6f586848 Mon Sep 17 00:00:00 2001 From: Ibrahim Wassouf Date: Fri, 7 Jul 2023 19:59:52 -0300 Subject: [PATCH 4/4] Update erDiagram to make entity names in singular form --- cypress/integration/rendering/erDiagram.spec.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cypress/integration/rendering/erDiagram.spec.js b/cypress/integration/rendering/erDiagram.spec.js index 91c93b6a85..c125d6f747 100644 --- a/cypress/integration/rendering/erDiagram.spec.js +++ b/cypress/integration/rendering/erDiagram.spec.js @@ -204,13 +204,13 @@ describe('Entity Relationship Diagram', () => { imgSnapshotTest( ` erDiagram - BOOKS { + BOOK { int *id string name varchar(99) summary } - BOOKS }o..o{ STORES : sold - STORES { + BOOK }o..o{ STORE : soldBy + STORE { int *id string name varchar(50) address