Reputation: 1202
I have a lot of experience using Hibernate to reverse engineer entity classes (Java) from the DB instance, (this process is the 'reverse' of evolving the DB based on writing entity classes). Often, with existing data and processes, it is essential to treat the DB as the single 'source of truth' and create entities based on the DB.
I'm interested in using Prisma (TS/JS), and I've been looking for generators which can generate Prisma schema (which is used to generate entity classes) based on an existing DB (reverse engineering).
Is there a way to reverse engineer the Prisma schema from an existing DB? Are there any known projects to add this functionality?
Upvotes: 4
Views: 1413
Reputation: 7268
I believe you're looking for Prisma's introspection feature. According to the Introspection Concept Article in the Prisma docs:
You can introspect your database using the Prisma CLI in order to generate the data model in your Prisma schema.
....
Introspection is often used to generate an initial version of the data model when adding Prisma to an existing project.
The prisma cli
command for introspection once you have the database connection set up:
npx prisma introspect
This should update your Prisma Schema file with the existing database tables.
Upvotes: 3