JTBDOS
uses Neon as the database provider with Prisma as the ORM as well as Clerk for authentication. This guide will provide the steps you need to switch the database provider from Neon to Supabase. This guide is based on a few existing resources, including Supabase’s guide and Prisma’s guide.
For authentication, another guide will be provided to switch to Supabase Auth with feature parity to Clerk like organization management, user roles, and more (coming soon).
JTBDOS
project.
1. Sign up to Supabase
Create a free account at supabase.com. You can manage your projects through the Dashboard or use the Supabase CLI. We’ll be using both the Dashboard and CLI throughout this guide.2. Create a Project
Create a new project from the Supabase Dashboard. Give it a name and choose your preferred region. Once created, you’ll get access to your project’s connection details. Head to the Settings page, then click on Database. We’ll need to keep track of the following for the next step:- The Database URL in
Transaction
mode, with the port ending in6543
. We’ll call thisDATABASE_URL
. - The Database URL in
Session
mode, with the port ending in5432
. We’ll call thisDIRECT_URL
.
3. Update the environment variables
Update the.env
file with the Supabase connection details. Make sure you add ?pgbouncer=true&connection_limit=1
to the end of the DATABASE_URL
value.
.env
pgbouncer=true
disables Prisma from generating prepared statements. This is required since our connection pooler does not support prepared statements in transaction mode yet. The connection_limit=1
parameter is only required if you are using Prisma from a serverless environment.4. Replace the dependencies
Prisma doesn’t have a Supabase adapter yet, so we just need to remove the Neon adapter and connect to Supabase directly. First, remove the Neon dependencies from the project…Terminal
Terminal
5. Update the database package
Update thedatabase
package. We’ll remove the Neon extensions and connect to Supabase directly, which should automatically use the environment variables we set earlier.
packages/database/index.ts
6. Update the Prisma schema
Update theprisma/schema.prisma
file so it contains the DIRECT_URL
. This allows us to use the Prisma CLI to perform other actions on our database (e.g. migrations) by bypassing Supavisor.
prisma/schema.prisma
JTBDOS
project:
Terminal