P
Prisma2mo ago
Niels

Way to run migrations & seeding using the PrismaClient

Hi, is it possible to run the migrations and seedings for Prisma at runtime using the PrismaClient instance? Would prevent me from having to bundle all source files into my docker containers as well, since its all compiled down.
4 Replies
jonfanz
jonfanz2mo ago
No, generally that’s done outside of runtime. For Docker you could build separate containers for running migrations and the application?
Niels
NielsOP2mo ago
Yeah, exactly. I wanted to speed up the pipeline, so I included my source code in the container. However, the container grew 100 times larger in size and took 2 times longer to build (over 10 minutes). Just to give an idea of why I would need it: Fortunately, with seeding, I can now manually call my seed script (by including the seed.ts file in my instrumentations for NextJS depending on an env var) to achieve the same result. However, there doesn’t seem to be a way to do this for migrations which has to be done in all environments and forces me to include pnpm and prisma at runtime. If there was an option to run migrations with the client, since the required binaries and files are already compiled and included, it would be much more efficient I’d say. Technically, would it be possible to code an extension like this myself or is that not easy to achieve without editing the prisma source? Looks like I'm not the only one: https://github.com/prisma/prisma/issues/4703
GitHub
Prisma Migrate: programmatic access to CLI commands (deploy, `res...
Problem It would be nice to have a way to run the migrate programmatically. I am running into an issue where my api is using lambdas (serverless) and my database is only accessible from within an a...
jonfanz
jonfanz2mo ago
Yeah unfortunately that’s an open issue for us. As for a client extension, no, because Prisma migrate is pretty much totally distinct from the client. It’s not possible to work with it. I mean it is if you use exec and open up a new process, but not in a convenient way
Niels
NielsOP2mo ago
Yeah, got it. Well, using exec still means downloading the cli at runtime again. No probs, thanks.
Want results from more Discord servers?
Add your server