frankc1619
PPrisma
•Created by frankc1619 on 2/18/2025 in #help-and-questions
Multi Project (Database) Set-up With Prisma and Neon
Hi all,
I am currently investigating a project per user set up for my multi-tenant application which uses Neon, Prisma ORM and Next.js hosted in Vercel.
I have played around with the Neon API and was able to create a new project and run migrations on that project as soon as a new user logs in to the application.
All good so far.
However, I realised one issue at the point where requests are made to my database via Prisma. That is, usually the Prisma Client is only instantiated once and database url is defined once with:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
This is a problem as I will have many DATABASE_URL variables with this set up.
I think creating new Prisma Client instances for each request is a bad idea.
Any advice to get around this?
Maybe this is the wrong direction, but Neon makes it so easy and cheap to have a database per user and I would like to pursue it if possible, not least because my particular type of user values data security a lot (more of a peace of mind thing).5 replies
PPrisma
•Created by frankc1619 on 10/25/2024 in #help-and-questions
Prisma Migrations: local, dev and prod
Hi all,
I have a specific question on Prisma migrations with next.js and Vercel. For my project I have 3 postgresQL database versions:
- Local composed with docker
- Dev/preview hosted on Vercel
- Prod hosted on Vercel
There are two pipelines that Vercel runs when linked to my github repo - one to deploy to a preview environment when a PR is opened and one to deploy to prod when a PR is merged to main.
I want to make sure any migrations and database changes are tested first in the preview database, and then (if ok) can be applied to the prod database when the PR is merged with main.
My question is: what is the process with this setup? Is this advisable? And if so, how should I change my package.json scripts? Currently I just run
prisma migrate deploy
post install and prisma generate && next build
when running build.
To summarise, I think my ideal scenario would be (but this could be wrong and please tell me if it is):
1) When making changes to schema before PR, developer creates migration files then commits these along with PR
2) When PR is opened, pipeline runs to deploy to preview env and runs migration files on the preview db
3) When PR is approved and merged, pipeline runs to deploy to prod env and runs migration files on prod db
4) When a developer pulls main, they also run the new migration files from main on their local db1 replies