diff --git a/apps/docs/content/guides/database/prisma.mdx b/apps/docs/content/guides/database/prisma.mdx index 31ea39f16e5..b72c2f8294f 100644 --- a/apps/docs/content/guides/database/prisma.mdx +++ b/apps/docs/content/guides/database/prisma.mdx @@ -78,7 +78,8 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t ```bash npm init -y - npm install prisma typescript ts-node @types/node --save-dev + npm install prisma tsx @types/pg --save-dev + npm install @prisma/client @prisma/adapter-pg dotenv pg npx tsc --init @@ -87,8 +88,9 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t ```bash - pnpm init -y - pnpm install prisma typescript ts-node @types/node --save-dev + pnpm init + pnpm install prisma tsx @types/pg --save-dev + pnpm install @prisma/client @prisma/adapter-pg dotenv pg pnpx tsc --init @@ -98,7 +100,8 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t ```bash yarn init -y - yarn add prisma typescript ts-node @types/node --save-dev + yarn add prisma tsx @types/pg --save-dev + yarn add @prisma/client @prisma/adapter-pg dotenv pg npx tsc --init @@ -108,7 +111,8 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t ```bash bun init -y - bun install prisma typescript ts-node @types/node --save-dev + bun install prisma tsx @types/pg --save-dev + bun install @prisma/client @prisma/adapter-pg dotenv pg bunx tsc --init @@ -168,15 +172,6 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t postgres://prisma.[PROJECT-REF]... ``` - In your schema.prisma file, edit your `datasource db` configs to reference your DIRECT_URL - ```text schema.prisma - datasource db { - provider = "postgresql" - url = env("DATABASE_URL") - directUrl = env("DIRECT_URL") - } - ``` - @@ -190,9 +185,56 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t - + - If you have already modified your Supabase database, synchronize it with your migration file. Otherwise create new tables for your database + Add `import "dotenv/config"` to the generated `prisma.config.ts`. If you are using a serverless environment, change the data source URL to `DIRECT_URL`. + + + + + + + ```ts prisma.config.ts + import "dotenv/config"; + import { defineConfig, env } from "prisma/config"; + + export default defineConfig({ + schema: "prisma/schema", + migrations: { + path: "prisma/migrations", + }, + datasource: { + url: env("DATABASE_URL"), + }, + }); + ``` + + + ```ts prisma.config.ts + import "dotenv/config"; + import { defineConfig, env } from "prisma/config"; + + export default defineConfig({ + schema: "prisma/schema", + migrations: { + path: "prisma/migrations", + }, + datasource: { + url: env("DIRECT_URL"), + }, + }); + ``` + + + + + + + + + + + If you have already modified your Supabase database, synchronize it with your migration file. Otherwise create new tables for your database, then generate the Prisma client. @@ -232,25 +274,25 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t ```bash npx prisma migrate dev --name first_prisma_migration - + npx prisma generate ``` ```bash pnpx prisma migrate dev --name first_prisma_migration - + pnpx prisma generate ``` ```bash npx prisma migrate dev --name first_prisma_migration - + npx prisma generate ``` ```bash bunx prisma migrate dev --name first_prisma_migration - + bunx prisma generate ``` @@ -291,6 +333,7 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t ```bash npx prisma migrate resolve --applied 0_init_supabase + npx prisma generate ``` @@ -319,6 +362,7 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t ```bash pnpx prisma migrate resolve --applied 0_init_supabase + pnpx prisma generate ``` @@ -347,6 +391,7 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t ```bash npx prisma migrate resolve --applied 0_init_supabase + npx prisma generate ``` @@ -375,6 +420,7 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t ```bash bunx prisma migrate resolve --applied 0_init_supabase + bunx prisma generate ``` @@ -385,47 +431,6 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t - - - - Install the Prisma client and generate its model - - - - - - ```sh - npm install @prisma/client - npx prisma generate - ``` - - - ```sh - pnpm install @prisma/client - pnpx prisma generate - ``` - - - ```sh - yarn add @prisma/client - npx prisma generate - ``` - - - ```sh - bun install @prisma/client - bunx prisma generate - ``` - - - - @@ -433,13 +438,15 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t ```ts index.ts - const { PrismaClient } = require('@prisma/client'); + import "dotenv/config"; + import { PrismaClient } from "./generated/prisma/client"; + import { PrismaPg } from "@prisma/adapter-pg"; - const prisma = new PrismaClient(); + const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL }); + export const prisma = new PrismaClient({ adapter }); async function main() { - //change to reference a table in your schema - const val = await prisma..findMany({ + const val = await prisma.user.findMany({ take: 10, }); console.log(val); @@ -452,10 +459,10 @@ If you plan to solely use Prisma instead of the Supabase Data API (PostgREST), t .catch(async (e) => { console.error(e); await prisma.$disconnect(); - process.exit(1); + process.exit(1); }); - ``` + diff --git a/apps/docs/content/guides/database/prisma/prisma-troubleshooting.mdx b/apps/docs/content/guides/database/prisma/prisma-troubleshooting.mdx index fb0f3bd2511..ff3757e0eab 100644 --- a/apps/docs/content/guides/database/prisma/prisma-troubleshooting.mdx +++ b/apps/docs/content/guides/database/prisma/prisma-troubleshooting.mdx @@ -142,18 +142,16 @@ A Prisma migration is referencing a schema it is not permitted to manage. ### Solutions: [#solutions-cross-schema-references] -- Multi-Schema support: If the external schema isn't Supabase managed, modify your `prisma.schema` file to enable the multi-Schema preview +- Multi-schema support: If the external schema isn't Supabase managed, list the relevant schemas on the `datasource` block in your `schema.prisma` file. -```ts prisma.schema +```prisma schema.prisma generator client { - provider = "prisma-client-js" - previewFeatures = ["multiSchema"] //Add line + provider = "prisma-client" + output = "../generated/prisma" } datasource db { provider = "postgresql" - url = env("DATABASE_URL") - directUrl = env("DIRECT_URL") schemas = ["public", "other_schema"] //list out relevant schemas } ```