Deploy Serverless to Vercel

You first need to change the defined datasource in

db/schema.prisma from SQLite to Postgres

  1. -datasource sqlite {- provider = "sqlite"- url = "file:./db.sqlite"-+datasource postgresql {+ provider = "postgresql"+ url = env("DATABASE_URL")+}

Assuming you already have a

Vercel account:

  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 “Transaction”
  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 NODE_ENV=production blitz prisma migrate deploy --preview-feature && blitz build so that the production DB will be migrated on each deploy
  5. Add your DB url as a secret environment variable using the UI or by running vercel env add DATABASE_URL
  6. Add your SESSION_SECRET_KEY environment variable (It needs to be 32 characters long)
  7. Run git push if using the Git Integration or vercel if using Vercel CLI

Tip: For optimal response times locate your database and vercel deployment in the same region.