prisma-case-format
As of prisma@2.19.0
, prisma introspect
will name its model 1:1 with your database's conventions. That's great, but if your db is purely snake_case
, or worse if your tables lack any common convention, it can make the autogenerated client code less pleasant to consume. prisma-case-format
will format your prisma schema's model and field names to enforce a more conventional experience.
Use-case: as a one-time migration assistant
Use --dry-run
to figure out which case conventions are correct for your project. Once things look correct, drop the flag to save changes to the --file
(or your local schema.prisma
by default).
Use-case: as a small CI/CD component
prisma-case-format
aims to be idempotent, so you can use it to confirm that case conventions in your schema.prisma
have not accidentally drifted. prisma-case-format
can be applied on-commit or on-push, either in a git commit-hook package or as a CI/CD step. Use --dry-run
to diff changes with the original file, or backup the original and compare to the edit.
Usage
❯ prisma-case-format --help
Usage: prisma-case-format [options]
Give your schema.prisma sane naming conventions
Options:
--file <file> cwd-relative path to schema.prisma file (default: "schema.prisma")
-D, --dry-run print changes to console, rather than back to file (default: false)
--table-case <tableCase> case convention for table names (SEE BOTTOM) (default: "pascal")
--field-case <fieldCase> case convention for field names (default: "camel")
--enum-case <enumCase> case convention for enum names
--map-table-case <mapTableCase> case convention for @@map() annotations (SEE BOTTOM)
--map-field-case <mapFieldCase> case convention for @map() annotations
--map-enum-case <mapEnumCase> case convention for @@map() annotations on enums
-p, --pluralize optionally pluralize array type fields (default: false)
-V, --version hint: you have v1.7.1
-h, --help display help for command
Supported case conventions: ["pascal", "camel", "snake"].
Additionally, append ',plural' after any case-convention selection to mark case convention as pluralized.
For instance:
--map-table-case=snake,plural
will append `@@map("users")` to `model User`.
Append ',singular' after any case-convention selection to mark case convention as singularized.
For instance,
--map-table-case=snake,singular
will append `@@map("user")` to `model Users`
Example
// schema.prisma before
...
model house_rating {
id Int @id @default(autoincrement())
house_id String
house house @relation(fields: [house_id], references: [id])
...
}
...
model house {
id String @id @default(uuid())
house_rating house_rating[]
...
}
...
❯ prisma-case-format
✨ Done.
// schema.prisma after
...
model HouseRating {
id Int @id @default(autoincrement())
houseId String @map("house_id")
house House @relation(fields: [houseId], references: [id])
...
@@map("house_rating")
}
...
model House {
id String @id @default(uuid())
houseRating HouseRating[]
...
@@map("house")
}
...
Supply the -p
or --pluralize
argument to get array pluralizations.
❯ prisma-case-format -p
✨ Done.
// schema.prisma after pluralization
...
model House {
...
houseRatings HouseRating[]
ownerContacts String[] @map("owner_contact")
...
}
...