Builder's DayOctober 26 · SFGet tickets

Prisma 8 extension

Supabase

Supabase auth and storage tables plus role-bound clients for row-level security.

By PrismaExperimentalPostgreSQL

What it does

Ships a contract of every Supabase-managed auth and storage table and the anon, authenticated, and service_role roles, so your app can reference them without emitting migrations for them. The runtime adds asUser(jwt), asAnon(), and asServiceRole() to bind the Postgres role and JWT claims per request.

Register it in the config

prisma.config.ts
import { definePrismaConfig } from 'prisma/config';
import supabasePack from '@prisma/orm-extension-supabase/pack';
import { defineConfig as ormConfig } from '@prisma/orm-postgres/config';

export default definePrismaConfig({
  orm: ormConfig({
    contract: './src/prisma/contract.prisma',
    extensions: [supabasePack],
    db: {
      connection: process.env['DATABASE_URL']!,
    },
  }),
});

Create the role-bound client

src/prisma/db.ts
import { supabase } from '@prisma/orm-extension-supabase/runtime';
import type { Contract } from './contract.d';
import contractJson from './contract.json' with { type: 'json' };

export const db = supabase<Contract>({
  contractJson,
  url: process.env['DATABASE_URL']!,
  jwtSecret: process.env['SUPABASE_JWT_SECRET']!,
});

// Per request: db.asUser(jwt), db.asAnon(), or db.asServiceRole().

Then run npx prisma@latest db init, or db update on an existing database. The extension ships its own migration for anything the database needs installed. Full walkthrough in the extensions docs.