Skip to content

Commit

Permalink
Merge pull request #4588 from ibrahimWassouf/enhancement/4158_Add_pri…
Browse files Browse the repository at this point in the history
…mary_key_beginning_with_asterisk

Allow entity diagram attribute names to start with asterisk
  • Loading branch information
sidharthv96 authored Jul 17, 2023
2 parents 5e6d42c + 9b9671b commit 48a49b1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
21 changes: 21 additions & 0 deletions cypress/integration/rendering/erDiagram.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ describe('Entity Relationship Diagram', () => {
);
});

it('should render entities with attributes that begin with asterisk', () => {
imgSnapshotTest(
`
erDiagram
BOOK {
int *id
string name
varchar(99) summary
}
BOOK }o..o{ STORE : soldBy
STORE {
int *id
string name
varchar(50) address
}
`,
{ loglevel: 1 }
);
cy.get('svg');
});

it('should render entities with keys', () => {
renderGraph(
`
Expand Down
2 changes: 1 addition & 1 deletion docs/syntax/entityRelationshipDiagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 12 additions & 2 deletions packages/mermaid/src/diagrams/er/parser/erDiagram.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 48a49b1

Please sign in to comment.