How to create a new database w/ schema from Node - not CLI?
Hey all, trying to figure a problem out. I'm building a desktop app (Electron, Node, React, Prisma, etc) that will run from user's computer. In my use case users can create multiple instances of the app - think a different savegame in a video game. For this, I would really like to have different databases for each instance - db1.db, db2.db, db3.db, etc. I know how to solve this with storing all the data in one Sqlite db and indexing etc, but would prefer totally different DBs
I know how to do all of this from CLI with db push, migrate, and other commands. But can't figure out how to do it from Node itself
What I would like to do is if a user creates a new instance, I build a filename and path, then create the new datbase file w/ schema at that location. And a PrismaClient instance is created for it.
Is this possible? Most of my searching hasn't been successful. Thanks!
2 Replies
You're in no rush, so we'll let a dev step in. Enjoy your coffee, or drop into
#ask-ai
if you get antsy for a second opinion!Hey 👋
If I understand correctly, you want to programatically run
db push
, migrate dev
commands from your node script and not from the CLI, right?
Does this feature request cover what you are trying to do:
https://github.com/prisma/prisma/issues/4703GitHub
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...