Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share Prisma Types Between Microservices

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?

like image 493
Jest Games Avatar asked Jan 29 '26 21:01

Jest Games


2 Answers

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.

like image 148
user13880436 Avatar answered Jan 31 '26 13:01

user13880436


Updated Answer from the Author

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": []
  },
]```
like image 41
Decoded Avatar answered Jan 31 '26 14:01

Decoded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!