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 the now cli installed, you can do the following:

  1. You need a production Postgres database. It's straightforward to set this up on Digital Ocean.
  2. You also need a connection pool. This is also relatively straightforward to set up on Digital Ocean.
    1. Read the Digital Ocean docs on setting up your connection pool
    2. Ensure you set your "Pool Mode" to be "Session" instead of "Transaction" (because of a bug in Prisma)
  3. You need your entire database connection string. If you need, read the Prisma docs on this.
    1. Make sure you get the connection string to your connection pool, not directly to the DB.
    2. 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.
  4. 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
  5. Add your DB url as a secret environment variable by running now secrets add @database-url "DATABASE_CONNECTION_STRING"
  6. Add a now.json at your project root with
{
"env": {
"DATABASE_URL": "@database-url"
},
"build": {
"env": {
"DATABASE_URL": "@database-url"
}
}
}
  1. 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!))
  2. Run now
Idea for improving this page?Edit it on Github