How to change the database provider to Supabase.
Supabase is an open source Firebase alternative providing a Postgres database, Authentication, instant APIs, Edge Functions, Realtime subscriptions, and Storage.
SuperStarter
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).
Here’s how to switch from Neon to Supabase for your SuperStarter
project.
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.
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:
Transaction
mode, with the port ending in 6543
. We’ll call this DATABASE_URL
.Session
mode, with the port ending in 5432
. We’ll call this DIRECT_URL
.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.
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.
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…
… and add the Supabase dependencies:
Update the database
package. We’ll remove the Neon extensions and connect to Supabase directly, which should automatically use the environment variables we set earlier.
Update the prisma/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.
Now you can run the migration from the root of your SuperStarter
project: