Deploy Serverless to Vercel
You first need to change the defined datasource in
db/schema.prisma
from SQLite to Postgres-datasource sqlite {- provider = "sqlite"- url = "file:./db.sqlite"-+datasource postgresql {+ provider = "postgresql"+ url = env("DATABASE_URL")+}
Assuming you already have a
Vercel account:- You need a production Postgres database. It's straightforward to set this up on Digital Ocean.
- You also need a connection pool. This is also relatively straightforward to set up on Digital Ocean.
- Read the Digital Ocean docs on setting up your connection pool
- Ensure you set your "Pool Mode" to be "Session" instead of "Transaction" (because of a bug in Prisma)
- You need your entire database connection string. If you need, read the Prisma docs on this.
- Make sure you get the connection string to your connection pool, not directly to the DB.
- If using pgBouncer (default connection pool on Digital Ocean), you must add
?pgbouncer=true
to the end of your connection string for Prisma to work correctly.
- Change your build script in package.json to be
blitz db migrate && blitz build
so that the production DB will be migrated on each deploy - Add your DB url as a secret environment variable using the UI or by running
vercel env add DATABASE_URL
- Run
git push
if using the Git Integration orvercel
if using Vercel CLI