Supabase is an open source Firebase alternative providing a Postgres database, Authentication, instant APIs, Edge Functions, Realtime subscriptions, and Storage.

next-forge 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 next-forge 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 in 6543. We’ll call this DATABASE_URL.
  • The Database URL in Session mode, with the port ending in 5432. We’ll call this DIRECT_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
DATABASE_URL="postgres://postgres:postgres@127.0.0.1:54322/postgres?pgbouncer=true&connection_limit=1"
DIRECT_URL="postgres://postgres:postgres@127.0.0.1:54322/postgres"

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
pnpm remove @neondatabase/serverless @prisma/adapter-neon ws @types/ws --filter @repo/database

… and add the Supabase dependencies:

Terminal
pnpm install -D supabase --filter @repo/database

5. Update the database package

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.

packages/database/index.ts
import 'server-only';
import { PrismaClient } from '@prisma/client';

export const database = new PrismaClient();

export * from '@prisma/client';

6. Update the Prisma schema

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.

prisma/schema.prisma
datasource db {
  provider     = "postgresql"
  url          = env("DATABASE_URL")
  directUrl    = env("DIRECT_URL")
  relationMode = "prisma"
}

Now you can run the migration from the root of your next-forge project:

Terminal
pnpm run migrate