Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support NOT NULL attribute key for erDiagram syntax #4429

Open
gvenzl opened this issue May 25, 2023 · 4 comments
Open

Support NOT NULL attribute key for erDiagram syntax #4429

gvenzl opened this issue May 25, 2023 · 4 comments
Labels
Graph: Entity Relationship Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request

Comments

@gvenzl
Copy link

gvenzl commented May 25, 2023

Proposal

Mermaid.js should add the attribute key NN for erDiagrams to model NOT NULL database columns.

NOT NULL is a widely used concept in relational databases to enforce the existence of a value for a field. Mermaid already supports PK, FK and UK, for Primary Key, Foreign Key and Unique Key attributes (https://mermaid.js.org/syntax/entityRelationshipDiagram.html#attribute-keys-and-comments) yet does not provide any facility to mark a column NOT NULL other than manually typing a comment for it, i.e.:

erDiagram
    BOOKS {
        int    id     PK "NN"
        string title     "NN"
        int    isbn      "NN"
        date   published
        string genre
    }

The changes look fairly isolated to

<block>\b((?:PK)|(?:FK)|(?:UK))\b return 'ATTRIBUTE_KEY'

Example

The new syntax would look like this:

erDiagram
    BOOKS {
        int    id         PK NN
        string title         NN
        int    isbn          NN
        date   published
        string genre
    }

Marking id, title and isbn all NN as NOT NULL.

Screenshots

Current, as comment approach:

image image
@gvenzl gvenzl added Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request labels May 25, 2023
@tomperr
Copy link
Contributor

tomperr commented Jun 7, 2023

It's a simple improvement: as you explained, just change the grammar (and also add tests, examples and documentation about it) to allow "NN". I'm just wondering whether "NN" for "Not Null" is clear enough. "PK", "FK", "UK" are common abbreviations, but I'm not sure about "NN" (I'm not a native English speaker, so that might explain my point of view).

@Haratsu
Copy link

Haratsu commented Oct 23, 2023

It's a simple improvement: as you explained, just change the grammar (and also add tests, examples and documentation about it) to allow "NN". I'm just wondering whether "NN" for "Not Null" is clear enough. "PK", "FK", "UK" are common abbreviations, but I'm not sure about "NN" (I'm not a native English speaker, so that might explain my point of view).

NN is quite common as SQL standard uses "NOT NULL" keyword to indicate the behaviour. A (more complex) solution would be to add a column "Nullability" with values "Yes" / "No", but personally I do not see any benefit on adding a column for binary labels.

In general you might need to think about "custom" or "optional" attributes, As there are plenty depending on which RDBMS is used, like e.g. "Autovalue" (MSSQL). But going that direction might end up in a bottomless pit.

@NikolayShakin
Copy link

I would add AI for the auto-increment attribute as well

@jjoaovitor7
Copy link

Discussion related: #3718

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Graph: Entity Relationship Status: Triage Needs to be verified, categorized, etc Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants