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 and thenow
cli installed, you can do the following:- 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 by running
now secrets add @database-url "DATABASE_CONNECTION_STRING"
- Add a
now.json
at your project root with
{"env": {"DATABASE_URL": "@database-url"},"build": {"env": {"DATABASE_URL": "@database-url"}}}
- Add
next
as a devDependency at the same version that Blitz includes (this is a temporary workaround until Blitz has first class support (very soon!)) - Run
now