Reputation: 455
I'm working on a project right now that has multiple TypeScript microservices performing operations on the same database. In each microservice, we are using the Prisma client to perform database operations. The issue I'm experiencing is we need to duplicate our schema.prisma
file in each microservice and generate the Prisma client for each service. Is there a way to manage our database in a separate project while sharing the generated client between the microservices without having duplicate schema.prisma
in each project?
Upvotes: 14
Views: 7669
Reputation: 1135
The way we handled it is using the assets
block, which enables copying generated assets into every micro service which wants to share the schema in the project.json which needs the dependency. This is a MonoRepo of course - e.g.
"assets": [
{
"input": "libs/prisma/luca/",
"output": "otherlocation/schema.prisma",
"glob": "**/schema.prisma",
"ignore": []
},
]```
Upvotes: 1
Reputation: 96
prisma generates a client from the schema. This client is as far as im aware totally independent of the schema files and the prisma package. If you copy those generated files in any way, you can reuse the client in a different project.
There is a nice article on medium using npm packages I guess. https://isidoro-ferreiro.medium.com/share-your-prisma-client-across-projects-44d1c7aca6fd
However u could also use something like nodemon or your ci pipeline to copy the generated client files to the other services.
Upvotes: 8