Skip to content

feat: add usePrismaNames option to draw schema names instead of db names - #296

Merged
keonik merged 1 commit into
mainfrom
feat/128-name-source
Aug 25, 2026
Merged

feat: add usePrismaNames option to draw schema names instead of db names#296
keonik merged 1 commit into
mainfrom
feat/128-name-source

Conversation

@keonik

@keonik keonik commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Closes #128

What

Adds an opt-in usePrismaNames generator option. By default models and fields carrying @@map / @map are drawn with their database names; with this option they keep the names as written in the schema.

model User {
  id       Int    @id
  nickName String @map("nick_name")

  @@map("users")
}
usePrismaNames Entity Field
false (default) users nick_name
true User nickName

Covers models, composite types, enums and fields — per @michaelaltmann's note on the issue that this should apply to columns too.

Drive-by fix: @@maped enums rendered twice

While wiring this up, the entity-name resolution turned out to be inconsistent. The enum block rendered enum.dbName || enum.name, but the relationship line only searched models/composite types, never enums — so it fell through to the enum's Prisma name:

erDiagram
        roles {
            ADMIN ADMIN
            USER USER
        }
    "accounts" |o--|| "Role" : "enum:role"
Loading

Mermaid draws that as an extra empty Role node next to the populated roles one. Relationship endpoints now resolve through the same displayName helper the entity blocks use, so both say roles.

Output change for existing users

For schemas using @@map, relationship endpoints are now consistently quoted:

-    "profile" |o--|| users : "user"
+    "profile" |o--|| "users" : "user"

Mermaid parses both identically — this is the same node, just quoted like every other endpoint already was. Verified against prisma/mappings.prisma; the rest of the output is byte-identical.

Testing

  • New __tests__/usePrismaNames.test.ts — both naming modes plus the enum-node regression. Renders to .md straight from the DMMF, so no browser needed.
  • Full suite (30 files / 35 tests) passes against Prisma 7.
  • Diffed generated output for prisma/mappings.prisma before/after to confirm the default path only changed in the two ways described above.

@keonik
keonik force-pushed the feat/128-name-source branch from e436f10 to e42a221 Compare August 19, 2026 19:19
Models and fields with @@Map / @Map are drawn with their database names.
usePrismaNames keeps the prisma schema names instead, for models, composite
types, enums and fields.

Also fixes an @@Map'ed enum rendering twice: the relationship line used the
enum's prisma name while the enum block used its database name, so mermaid
drew an extra empty node. Entity names on relationship lines are now resolved
through the same helper the entity blocks use.

Closes #128
@keonik
keonik force-pushed the feat/128-name-source branch from e42a221 to a6f5e32 Compare August 20, 2026 02:20
@keonik
keonik merged commit 6d57b83 into main Aug 25, 2026
35 of 36 checks passed
@keonik
keonik deleted the feat/128-name-source branch August 25, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow control over whether to use model name or db name

1 participant