The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Prisma guide updates
Alex Ruheni3f7c85599417
diff --git a/apps/docs/pages/guides/integrations/prisma.mdx b/apps/docs/pages/guides/integrations/prisma.mdxindex 2951c44b9d6..b2448f747da 100644--- a/apps/docs/pages/guides/integrations/prisma.mdx+++ b/apps/docs/pages/guides/integrations/prisma.mdx@@ -17,6 +17,7 @@ This guide explains how to quickly connect the Postgres database provided by Sup## Step 1: Get the connection string from Supabase project settingsGo to the settings page from the sidebar and navigate to the **Database** tab. You’ll find the database’s connection string with a placeholder for the password you provided when you created the project.+## Step 2: Testing the connection@@ -59,27 +60,17 @@ This starter also comes with the following packages installed:### Configuring the project-By default, Prisma migrations will try to drop the `postgres` database, which can lead to conflicts with Supabase databases. For this scenario, use [Prisma Shadow Databases](https://www.prisma.io/docs/concepts/components/prisma-migrate/shadow-database#cloud-hosted-shadow-databases-must-be-created-manually).--Create a shadow database in your PostgreSQL server within the same Supabase project using the `psql` CLI and the `DATABASE_URL` from the previous steps (or use the local database).--```bash-psql postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432-```--After you connect to your project's PostgreSQL instance, create another database (e.g., `postgres_shadow`):+Create a `.env` file at the root of your project:```bash-postgres=> CREATE DATABASE postgres_shadow;-postgres=> exit+touch .env```-In the `.env` file, update `DATABASE_URL` and `SHADOW_DATABASE_URL` to the connection string from **step 1**. The `.env` file should look like:+In the `.env` file, add a `DATABASE_URL` variable and add the connection string from **step 1**. The `.env` file should look like:```env# .envDATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres"-SHADOW_DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres_shadow"```This is what your `schema.prisma` file should look like:@@ -88,7 +79,6 @@ This is what your `schema.prisma` file should look like:datasource db {provider = "postgresql"url = env("DATABASE_URL")- shadowDatabaseUrl = env("SHADOW_DATABASE_URL")}generator client {@@ -153,7 +143,7 @@ Update your `.env` file with the following changes:1. Rename the `DATABASE_URL` environment variable to `DIRECT_URL`1. Create a `DATABASE_URL` environment variable and paste in the new connection string from the dashboard as its value-It is recommended to minimize the number of concurrent connections by setting the `connection_limit` to `1`. You can set connection limit by appending `?connection_limit=1` to your connection string+Append the `?pgbouncer=true` flag to the `DATABASE_URL` variable. It is recommended to minimize the number of concurrent connections by setting the `connection_limit` to `1`. You can set connection limit by appending `?connection_limit=1` to your connection string.Your `.env` file should resemble the following:@@ -162,9 +152,8 @@ Your `.env` file should resemble the following:# PostgreSQL connection string used for migrationsDIRECT_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:6543/postgres"# PostgreSQL connection string with pgBouncer config — used by Prisma Client-DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:6543/postgres?connection_limit=1"+DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:6543/postgres?pgbouncer=true&connection_limit=1"-SHADOW_DATABASE_URL="postgres://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgres_shadow"```Update your Prisma schema by setting the `directUrl` in the datasource block:@@ -174,7 +163,6 @@ datasource db {provider = "postgresql"url = env("DATABASE_URL")directURL = env("DIRECT_URL")- shadowDatabaseUrl = env("SHADOW_DATABASE_URL")}```@@ -184,7 +172,7 @@ If you want to learn more about Prisma, check out the [docs](https://www.prisma.## Troubleshooting-### 1. Missing grants+### Missing grantsIf you run `prisma migrate dev --name init` multiple times, it sometimes asks if you want to recreate the whole schema. If you chose yes, it will delete the public schema and recreate it. The default grants are missing after this.@@ -204,16 +192,15 @@ alter default privileges in schema public grant all on sequences to postgres, anRun `prisma migrate dev` to apply the draft migration to the database.-### 2. Using Prisma with multiple PostgreSQL schemas+### Using Supabase auth with Prisma-If you're using multiple database schemas, enable the `multiSchema` Preview feature flag in the `generator` block of your Prisma schema:+If you would like to use Supabase auth and Prisma in your application, you will have to enable the `multiSchema` Preview feature flag in the `generator` block of your Prisma schema:```godatasource db {provider = "postgresql"url = env("DATABASE_URL")directURL = env("DIRECT_URL")- shadowDatabaseUrl = env("SHADOW_DATABASE_URL")}generator client {@@ -229,7 +216,6 @@ datasource db {provider = "postgresql"url = env("DATABASE_URL")directURL = env("DIRECT_URL")- shadowDatabaseUrl = env("SHADOW_DATABASE_URL")schemas = ["public", "auth"]}@@ -252,7 +238,17 @@ model User {To learn more about using Prisma with multiple database schemas, refer to [this page in the Prisma docs](https://www.prisma.io/docs/guides/database/multi-schema#learn-more-about-the-multischema-preview-feature).-### 3. Enabling PosgreSQL extensions+### Using Supabase Row Level Security with Prisma++If you would like to use Supabase Row Level Security (RLS) with Prisma, check out the following++Check out the [Prisma Client Extension - Row Level Security example](https://github.com/prisma/prisma-client-extensions/tree/main/row-level-security) that provides the primitives you could use to build and extend Prisma Client in PostgreSQL.++Also check out [useSupabaseRowLevelSecurity](https://github.com/dthyresson/prisma-extension-supabase-rls) Prisma Client extension that supports [Supabase RLS](/docs/guides/auth/row-level-security#authrole) and policies written to use [Supabase auth](/docs/guides/auth/overview).++The example and extension use [Prisma Client extensions](https://www.prisma.io/docs/concepts/components/prisma-client/client-extensions) Preview feature.++### Enabling PosgreSQL extensionsIf you would like to use a PostgreSQL extension with Prisma, enable the `postgresqlExtensions` Preview feature flag in the `generator` block of your Prisma schema:@@ -261,7 +257,6 @@ datasource db {provider = "postgresql"url = env("DATABASE_URL")directURL = env("DIRECT_URL")- shadowDatabaseUrl = env("SHADOW_DATABASE_URL")}generator client {@@ -277,7 +272,6 @@ datasource db {provider = "postgresql"url = env("DATABASE_URL")directURL = env("DIRECT_URL")- shadowDatabaseUrl = env("SHADOW_DATABASE_URL")extensions = [hstore(schema: "myHstoreSchema"), pg_trgm, postgis(version: "2.1")]}