Existing Database in snake_case
I'm running db pull on an existing database.... they are come in as snake_case. Anyway to auto convert these?
9 Replies
You've gone full bot mode! Let me fetch that AI answer for you ASAP.
Based on the knowledge sources provided, there is currently no built-in automatic way to convert snake_case table and column names to camelCase or PascalCase when running
prisma db pull
on an existing database. However, there are a few workarounds and potential solutions:
1. Manual Mapping: You can manually add @map
and @@map
attributes to your Prisma schema to map the snake_case database names to camelCase or PascalCase names in your Prisma Client API. This is described in the Prisma documentation.
2. Third-party Tools: There are some community-created tools that can help automate this process:
- prisma-case-format
- prisma-schema-transformer
These tools can be used to automatically transform snake_case to camelCase in your Prisma schema.
3. Feature Request: There is an open feature request on GitHub for Prisma to support global configuration for name casing. You can follow the progress of this issue: Support global config for name casing (table, fields).
While these solutions can help, it's important to note that automatic conversion is not currently a built-in feature of Prisma. The Prisma team is aware of this need and is collecting input on how to implement it in the future.
For now, you'll need to either manually adjust your schema or use one of the third-party tools mentioned above to achieve the desired naming convention in your Prisma Client API.Hey 👋
Did the AI response answer your question?
Let us know in case you still have any queries
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
@Nurul (Prisma) Not 100%.
I'm trying to work with an existing database with dozens of tables already created. They are all in snake_case as they should - but prisma does not convert.
Currently there is no functionality to automatically convert casing of table names.
This feature request would make it possible
GitHub
Support global config for name casing (table, fields) · Issue #8283...
Problem Mapping database table name and field name is tiring and counter productive both (creating new project or coming from existing database project) Suggested solution generator client { provid...
@Nurul (Prisma) Thanks - i really wish there was more support for users with exisitng databases. Kysely for instance converts it all perfectly.
@trojans10 i to will be struggling with existing db now that i have to migrate
seems very hard process
Yea, based on my experience the prisma workflow is best if you create and manage your schema in the code vs. pull from an existing db.
My problem is that it will want to delete your data, other than that it's ok.