samchon / prisma-markdown

Markdown generator of Prisma, including ERD and descriptions
MIT License
393 stars 18 forks source link

New tag `@minItems 1` #12

Closed samchon closed 9 months ago

samchon commented 9 months ago

Until yesterday, prisma-markdown could not distinguish whether 1: N relationships are mandatory or not. In such reason, prisma-markdown had drawn 1: N relationship as ||---|{ symbol regardless of the N position is whether mandatory or optional.

To make it clear, I've come with new idea @minItems 1 tag. If the tag being written on a 1: N relationship accessor, prisma-markdown will draw ||---|{ symbol. Otherwise it does not exist, ||---o{ symbol would be drawn instead.

model bbs_articles {
    id String @id @db.Uuid
    created_at DateTime @db.Timestamptz
    deleted_at DateTime? @db.Timestamptz

    //----
    // RELATIONS
    //----
    /// @minItems 1
    snapshots bbs_article_snapshots[]
    comments                bbs_article_comments[]
}
erDiagram
"bbs_articles" {
    String id PK
    DateTime created_at
    DateTime deleted_at "nullable"
}
"bbs_article_snapshots" {
    String id PK
    String bbs_article_id FK
    String format
    String title
    String body
    DateTime created_at
}
"bbs_article_comments" {
    String id PK
    String bbs_article_id FK
    String parent_id FK "nullable"
    DateTime created_at
    DateTime deleted_at "nullable"
}
"bbs_article_comment_snapshots" {
    String id PK
    String bbs_article_comment_id FK
    String format
    String body
    DateTime created_at
}
"bbs_article_snapshots" }|--|| "bbs_articles" : article
"bbs_article_comments" }o--|| "bbs_articles" : article
"bbs_article_comments" }o--o| "bbs_article_comments" : parent
"bbs_article_comment_snapshots" }|--|| "bbs_article_comments" : comment