diff --git a/.github/workflows/config/.linkspector.yml b/.github/workflows/config/.linkspector.yml
deleted file mode 100644
index 0d06293a36..0000000000
--- a/.github/workflows/config/.linkspector.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-dirs:
- - content
-useGitIgnore: true
-ignorePatterns:
- - pattern: "^/.*" # local links are not checked
- - pattern: "^http://localhost.*" # Localhost links are not checked
- - pattern: "^https://packagecontrol.*" # Package control links are not checked (it was 500ing at time of writing)
- - pattern: "^https://(www|dash).cloudflare.com.*" # Cloudflare links return 403 at time of writing
-
-fileExtensions:
- - mdx
- - md
-modifiedFilesOnly: false
-aliveStatusCodes:
- - 200
- - 201
- - 204
- - 304
- - 403
diff --git a/.github/workflows/linkspector.yml b/.github/workflows/linkspector.yml
deleted file mode 100644
index e428cf19b6..0000000000
--- a/.github/workflows/linkspector.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-name: Linkspector
-on: [pull_request]
-jobs:
- check-links:
- name: runner / linkspector
- runs-on: ubuntu-22.04
- permissions:
- contents: write
- steps:
- - uses: actions/checkout@v4
- - name: Run linkspector
- uses: umbrelladocs/action-linkspector@v1.3.7
- with:
- github_token: ${{ secrets.github_token }}
- reporter: github-pr-check
- fail_on_error: true
- filter_mode: nofilter
- config_file: .github/workflows/config/.linkspector.yml
\ No newline at end of file
diff --git a/.github/workflows/lychee.yml b/.github/workflows/lychee.yml
index 72cf3fa499..6bae422c2b 100644
--- a/.github/workflows/lychee.yml
+++ b/.github/workflows/lychee.yml
@@ -34,6 +34,7 @@ jobs:
--exclude 'http://localhost.*'
--exclude 'https://localhost.*'
--exclude 'https://cockroachlabs.com'
+ --exclude 'https://www.gnu.org'
--exclude '^/.*'
'./**/*.md' './**/*.mdx'
workingDirectory: "content"
@@ -60,6 +61,7 @@ jobs:
--exclude 'http://localhost.*'
--exclude 'https://localhost.*'
--exclude 'https://cockroachlabs.com'
+ --exclude 'https://www.gnu.org'
--exclude '^/.*'
'./**/*.md' './**/*.mdx'
workingDirectory: "content"
@@ -97,7 +99,7 @@ jobs:
fi
- name: 📝 Comment Broken Links
- if: ${{ always() && github.event.pull_request.head.repo.fork == false }}
+ if: ${{ always() && github.event.pull_request.head.repo.fork == false && (steps.lychee.outputs.exit_code != 0 || (steps.lychee-retry.conclusion != 'skipped' && steps.lychee-retry.outputs.exit_code != 0)) }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
diff --git a/content/100-getting-started/index.mdx b/content/100-getting-started/index.mdx
index b03a3857a7..110d5db0e6 100644
--- a/content/100-getting-started/index.mdx
+++ b/content/100-getting-started/index.mdx
@@ -3,7 +3,6 @@ title: 'Get Started'
metaTitle: 'Get started with Prisma'
metaDescription: 'Build data-driven applications with ease using Prisma ORM, add connection pooling or global caching with Prisma Accelerate.'
hide_title: true
-tocDepth: 1
sidebar_position: 0
sidebar_class_name: firstTitle
pagination_next: 'getting-started/quickstart-sqlite'
@@ -18,82 +17,60 @@ import {
Grid,
LinkCard,
List,
+ Plus,
+ Plug,
SignalStream,
PrismaPostgres,
SquareLogo,
+ QuickstartLinkCard
} from '@site/src/components/GettingStarted';
+Getting started
-
-
-Get started
-
-Welcome đź‘‹
-
-Explore our products that make it easy to build and scale data-driven applications:
-
-[**Prisma ORM**](/orm/overview/introduction/what-is-prisma) is a next-generation Node.js and TypeScript ORM that unlocks a new level of developer experience when working with databases thanks to its intuitive data model, automated migrations, type-safety & auto-completion.
-
-[**Prisma Postgres**](/postgres) is a managed PostgreSQL service that gives you an _always-on_ database with _pay-as-you-go_ pricing.
-
-[**Prisma Optimize**](/optimize/) helps you analyze queries, generate insights, and provides recommendations to make your database queries faster.
+
-[**Prisma Accelerate**](/accelerate) is a global database cache with scalable connection pooling to make your queries fast.
+
-
+[**Prisma ORM**](/orm/overview/introduction/what-is-prisma) is an open-source ORM that provides fast, type-safe access to Postgres, MySQL, SQLite, and more databases, and runs smoothly across Node.js, Bun, and Deno.
+```terminal
+npx prisma init --db
+```
+
+
-## Prisma ORM
+
-Add Prisma ORM to your application in a few minutes to start modeling your data, run schema migrations and query your database.
+[**Prisma Postgres**](/postgres) is a fully managed PostgreSQL database that scales to zero, integrates with Prisma ORM and Prisma Studio, and includes a generous free tier.
-### The easiest way to get started with Prisma
+```terminal
+npx create-db
+```
+
+
+
-_Explore all Prisma products at once._
+
-
+>
-### Explore quickly with a SQLite database
+The fastest way to set up **Prisma ORM** with a ready-to-use **Prisma Postgres** database.
-_These options don't require you to have your own database running._
+
-
-
-
-
+
+
-### Choose an option to get started with your own database
+### Already have your own database?
-_Select one of these options if you want to connect Prisma ORM to your own database._
+The fastest way to set Prisma ORM up with a ready-to-use database.
-
-
-
- Set up Prisma ORM from scratch with your favorite database and
- learn basic workflows like data modeling, querying, and migrations.
-
-
-
+
+
-
-
-
-
- Get started with Prisma ORM and your existing database by
- introspecting your database schema and learn how to query your database.
-
-
+
+
+
+
+
+ {/* ### Using Prisma Postgres with other tools?
+
+You can also use Prisma Postgres with different tools or ORMs. Pick one of the options below to see how to connect.
+
+
+
+
+
+ */}
+
+### Add Prisma to your favorite framework?
+
+Working with **Next.js**, **Remix**, or another framework? You can easily add Prisma to your setup in just a few steps and start using it right away.
+
+
-
-
-
-
-## Prisma Accelerate
-
-Make your database queries faster by scaling your database connections and caching database results at the edge with Prisma Accelerate.
-
-
-
-
-
-
-
-
-## Prisma Optimize
-
-Make your database queries faster by using the insights and recommendations generated by Prisma Optimize.
-
-
-
-
-
+
+
+
+
+
+
diff --git a/content/800-guides/010-data-migration.mdx b/content/800-guides/010-data-migration.mdx
index 24b98c97b6..9f8893c69c 100644
--- a/content/800-guides/010-data-migration.mdx
+++ b/content/800-guides/010-data-migration.mdx
@@ -61,7 +61,36 @@ model Post {
}
```
-### 1.2. Create a development branch
+### 1.2. Configure Prisma
+
+Create a `prisma.config.ts` file in the root of your project with the following content:
+
+```typescript file=prisma.config.ts
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+```
+
+:::note
+
+You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager:
+
+```bash
+npm install dotenv
+```
+
+:::
+
+### 1.3. Create a development branch
Create a new branch for your changes:
diff --git a/content/800-guides/020-implementing-schema-changes.mdx b/content/800-guides/020-implementing-schema-changes.mdx
index a5d8342766..83a4f30211 100644
--- a/content/800-guides/020-implementing-schema-changes.mdx
+++ b/content/800-guides/020-implementing-schema-changes.mdx
@@ -47,6 +47,35 @@ Source-controlling the `schema.prisma` file is not enough - you must include you
- Customized migrations contain information that cannot be represented in the Prisma schema
- The `prisma migrate deploy` command only runs migration files
+### 1.3. Configure Prisma
+
+Create a `prisma.config.ts` file in the root of your project with the following content:
+
+```typescript file=prisma.config.ts
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+```
+
+:::note
+
+You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager:
+
+```bash
+npm install dotenv
+```
+
+:::
+
## 2. Incorporate team changes
### 2.1. Pull latest changes
diff --git a/content/800-guides/030-migrate-from-typeorm.mdx b/content/800-guides/030-migrate-from-typeorm.mdx
index 210e5bd1be..4b852ac2b9 100644
--- a/content/800-guides/030-migrate-from-typeorm.mdx
+++ b/content/800-guides/030-migrate-from-typeorm.mdx
@@ -51,6 +51,35 @@ Update the `DATABASE_URL` in the `.env` file with your database connection strin
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE"
```
+### 2.3. Configure Prisma
+
+Create a `prisma.config.ts` file in the root of your project with the following content:
+
+```typescript file=prisma.config.ts
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+```
+
+:::note
+
+You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager:
+
+```bash
+npm install dotenv
+```
+
+:::
+
## 3. Migrate the database schema
### 3.1. Introspect your database
diff --git a/content/800-guides/040-migrate-from-sequelize.mdx b/content/800-guides/040-migrate-from-sequelize.mdx
index 4abf2e8fac..bc98456af4 100644
--- a/content/800-guides/040-migrate-from-sequelize.mdx
+++ b/content/800-guides/040-migrate-from-sequelize.mdx
@@ -78,6 +78,35 @@ Update the `DATABASE_URL` in the `.env` file with your database connection strin
DATABASE_URL="postgresql://USER:PASSWORD@HOST:PORT/DATABASE"
```
+### 1.3. Configure Prisma
+
+Create a `prisma.config.ts` file in the root of your project with the following content:
+
+```typescript file=prisma.config.ts
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+```
+
+:::note
+
+You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager:
+
+```bash
+npm install dotenv
+```
+
+:::
+
## 2. Migrate the database schema
### 2.1. Introspect your database
diff --git a/content/800-guides/050-migrate-from-mongoose.mdx b/content/800-guides/050-migrate-from-mongoose.mdx
index 3143c942f0..e9a4b2b306 100644
--- a/content/800-guides/050-migrate-from-mongoose.mdx
+++ b/content/800-guides/050-migrate-from-mongoose.mdx
@@ -78,6 +78,35 @@ Update the `DATABASE_URL` in the `.env` file with your MongoDB connection string
DATABASE_URL="mongodb://USER:PASSWORD@HOST:PORT/DATABASE"
```
+### 1.3. Configure Prisma
+
+Create a `prisma.config.ts` file in the root of your project with the following content:
+
+```typescript file=prisma.config.ts
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+```
+
+:::note
+
+You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager:
+
+```bash
+npm install dotenv
+```
+
+:::
+
## 2. Migrate the database schema
### 2.1. Introspect your database
diff --git a/content/800-guides/060-migrate-from-drizzle.mdx b/content/800-guides/060-migrate-from-drizzle.mdx
index 53b6e57d18..0fe8942aca 100644
--- a/content/800-guides/060-migrate-from-drizzle.mdx
+++ b/content/800-guides/060-migrate-from-drizzle.mdx
@@ -150,7 +150,36 @@ datasource db {
Once that's done, you can configure your [database connection URL](/orm/reference/connection-urls) in the `.env` file. Drizzle and Prisma ORM use the same format for connection URLs, so your existing connection URL should work fine.
-### 2.3. Introspect your database using Prisma ORM
+### 2.3. Configure Prisma
+
+Create a `prisma.config.ts` file in the root of your project with the following content:
+
+```typescript file=prisma.config.ts
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+```
+
+:::note
+
+You'll need to install the `dotenv` package to load environment variables. If you haven't already, install it using your package manager:
+
+```bash
+npm install dotenv
+```
+
+:::
+
+### 2.4. Introspect your database using Prisma ORM
With your connection URL in place, you can [introspect](/orm/prisma-schema/introspection) your database to generate your Prisma models:
@@ -170,7 +199,7 @@ model todo {
The generated Prisma model represents a database table. Prisma models are the foundation for your programmatic Prisma Client API which allows you to send queries to your database.
-### 2.4. Create a baseline migration
+### 2.5. Create a baseline migration
To continue using Prisma Migrate to evolve your database schema, you will need to [baseline your database](/orm/prisma-migrate/getting-started).
@@ -202,7 +231,7 @@ The command will mark `0_init` as applied by adding it to the `_prisma_migration
You now have a baseline for your current database schema. To make further changes to your database schema, you can update your Prisma schema and use `prisma migrate dev` to apply the changes to your database.
-### 2.5. Adjust the Prisma schema (optional)
+### 2.6. Adjust the Prisma schema (optional)
Models that are generated via introspection currently _exactly_ map to your database tables. In this section, you'll learn how you can adjust the naming of the Prisma models to adhere to [Prisma ORM's naming conventions](/orm/reference/prisma-schema-reference#naming-conventions).
diff --git a/content/800-guides/070-cloudflare-d1.mdx b/content/800-guides/070-cloudflare-d1.mdx
index 7264a75355..9dbb973915 100644
--- a/content/800-guides/070-cloudflare-d1.mdx
+++ b/content/800-guides/070-cloudflare-d1.mdx
@@ -179,7 +179,7 @@ CLOUDFLARE_D1_TOKEN="F8Cg..."
Ensure that you have a `prisma.config.ts` file set up in the root of your project with a [driver adapter](/orm/reference/prisma-config-reference#adapter) defined.
-```ts
+```typescript file=prisma.config.ts
import type { PrismaConfig } from 'prisma';
import { PrismaD1 } from '@prisma/adapter-d1';
@@ -191,6 +191,12 @@ export default {
adapter: true,
},
schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: process.env.DATABASE_URL!,
+ },
async adapter() {
return new PrismaD1({
CLOUDFLARE_D1_TOKEN: process.env.CLOUDFLARE_D1_TOKEN!,
diff --git a/content/800-guides/080-turborepo.mdx b/content/800-guides/080-turborepo.mdx
index 6580182f7b..f0dd46e806 100644
--- a/content/800-guides/080-turborepo.mdx
+++ b/content/800-guides/080-turborepo.mdx
@@ -94,7 +94,7 @@ Next, install the required dependencies to use Prisma ORM. Use your preferred pa
```terminal
npm install prisma --save-dev
-npm install @prisma/client
+npm install @prisma/client dotenv
```
@@ -103,7 +103,7 @@ npm install @prisma/client
```terminal
yarn add prisma --dev
-yarn add @prisma/client
+yarn add @prisma/client dotenv
```
@@ -112,7 +112,7 @@ yarn add @prisma/client
```terminal
pnpm add prisma --save-dev
-pnpm add @prisma/client
+pnpm add @prisma/client dotenv
```
@@ -222,6 +222,23 @@ model Post {
//add-end
```
+The `prisma.config.ts` file created in the `packages/database` directory should look like this:
+
+```typescript file=packages/database/prisma.config.ts
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+```
+
:::warning
It is recommended to add `../generated/prisma` to the `.gitignore` file because it contains platform-specific binaries that can cause compatibility issues across different environments.
@@ -335,7 +352,7 @@ Navigate to the project root and run the following command to automatically migr
-Generate your `prisma.schema`
+Generate your `schema.prisma`
To generate the types from Prisma schema, from the project root run:
diff --git a/content/800-guides/090-nextjs.mdx b/content/800-guides/090-nextjs.mdx
index 445d252b3e..1b55438503 100644
--- a/content/800-guides/090-nextjs.mdx
+++ b/content/800-guides/090-nextjs.mdx
@@ -139,17 +139,17 @@ This creates two models: `User` and `Post`, with a one-to-many relationship betw
To get access to the variables in the `.env` file, they can either be loaded by your runtime, or by using `dotenv`.
Include an import for `dotenv` at the top of the `prisma.config.ts`
-```ts
+```typescript file=prisma.config.ts
//add-start
import 'dotenv/config'
//add-end
import { defineConfig, env } from 'prisma/config';
+
export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: {
path: 'prisma/migrations'
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
@@ -218,9 +218,10 @@ main();
Now, tell Prisma how to run this script by updating your `prisma.config.ts`:
-```ts file=prisma.config.ts
+```typescript file=prisma.config.ts
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config';
+
export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: {
@@ -229,7 +230,6 @@ export default defineConfig({
seed: `tsx prisma/seed.ts`,
//add-end
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
diff --git a/content/800-guides/100-nuxt.mdx b/content/800-guides/100-nuxt.mdx
index c35659aa03..11aa72da40 100644
--- a/content/800-guides/100-nuxt.mdx
+++ b/content/800-guides/100-nuxt.mdx
@@ -62,7 +62,36 @@ To follow this guide, ensure you have the following:
});
```
-## 2. Setup Prisma ORM by running the development server locally
+## 2. Configure Prisma
+
+Before running the development server, create a `prisma.config.ts` file in the root of your project to manage environment variables and configuration:
+
+```typescript file=prisma.config.ts
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+```
+
+:::note
+
+You'll need to install the `dotenv` package to load environment variables:
+
+```bash
+npm install dotenv
+```
+
+:::
+
+## 3. Setup Prisma ORM by running the development server locally
After configuring your Nuxt project with the Prisma module, the next step is to set up Prisma ORM. This process begins by starting the development server, which automatically configures Prisma with a [SQLite database](/orm/overview/databases/sqlite).
@@ -121,7 +150,7 @@ Once the setup flow has terminated, it:
5. Installed and generated [Prisma Client](https://da-2255.docs-51g.pages.dev/orm/reference/prisma-client-reference) which enables you to query your DB.
6. Installed [Prisma Studio](/orm/tools/prisma-studio).
-When the Prisma setup is complete, the development server should start on `https://localhost:3000`.
+When the Prisma setup is complete, the development server should start on `https://localhost:3000`.
Next, stop the server, as we need to make some code changes.
diff --git a/content/800-guides/130-docker.mdx b/content/800-guides/130-docker.mdx
index b6d6e1684d..c8c24a5838 100644
--- a/content/800-guides/130-docker.mdx
+++ b/content/800-guides/130-docker.mdx
@@ -126,6 +126,33 @@ In the `schema.prisma` file, we specify a [custom `output` path](/orm/prisma-cli
:::
+Now, create a `prisma.config.ts` file in the root of your project:
+
+```typescript file=prisma.config.ts
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+```
+
+:::note
+
+You'll need to install the `dotenv` package to load environment variables:
+
+```bash
+npm install dotenv
+```
+
+:::
+
### 1.4. Create an Express.js server
With the Prisma schema in place, let's create an Express.js server to interact with the database. Start by creating an `index.js` file:
diff --git a/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx b/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx
index 388b68f1c8..45757bd01a 100644
--- a/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx
+++ b/content/800-guides/140-use-prisma-in-pnpm-workspaces.mdx
@@ -161,6 +161,35 @@ model User {
//add-end
```
+Now, create a `prisma.config.ts` file in the `database` package to configure Prisma:
+
+```typescript file=database/prisma.config.ts
+// add-start
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+// add-end
+```
+
+:::note
+
+You'll need to install the `dotenv` package to load environment variables from the `.env` file:
+
+```terminal
+pnpm add dotenv
+```
+
+:::
+
Next, add helper scripts to your `package.json` to simplify Prisma commands:
```json file=database/package.json
diff --git a/content/800-guides/150-multiple-databases.mdx b/content/800-guides/150-multiple-databases.mdx
index f3dd98f223..f304134f9c 100644
--- a/content/800-guides/150-multiple-databases.mdx
+++ b/content/800-guides/150-multiple-databases.mdx
@@ -146,6 +146,35 @@ model User {
//add-end
```
+Create a `prisma.config.ts` file for the user database:
+
+```typescript file=prisma-user-database/prisma.config.ts
+//add-start
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma-user-database/schema.prisma',
+ migrations: {
+ path: 'prisma-user-database/migrations',
+ },
+ datasource: {
+ url: env('PPG_USER_DATABASE_URL'),
+ },
+});
+//add-end
+```
+
+:::note
+
+You'll need to install the `dotenv` package if you haven't already:
+
+```terminal
+npm install dotenv
+```
+
+:::
+
Your user database schema is now ready.
### 2.2. Create a Prisma Postgres instance for post data
@@ -197,12 +226,31 @@ datasource db {
//add-start
model Post {
id Int @id @default(autoincrement())
- title String
+ title String
content String?
}
//add-end
```
+Create a `prisma.config.ts` file for the post database:
+
+```typescript file=prisma-post-database/prisma.config.ts
+//add-start
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma-post-database/schema.prisma',
+ migrations: {
+ path: 'prisma-post-database/migrations',
+ },
+ datasource: {
+ url: env('PPG_POST_DATABASE_URL'),
+ },
+});
+//add-end
+```
+
Your post database schema is now set.
### 2.3. Add helper scripts and migrate the schemas
diff --git a/content/800-guides/160-tanstack-start.mdx b/content/800-guides/160-tanstack-start.mdx
index 971908e4d4..a288dbd61b 100644
--- a/content/800-guides/160-tanstack-start.mdx
+++ b/content/800-guides/160-tanstack-start.mdx
@@ -390,7 +390,6 @@ export default defineConfig({
migrations: {
path: 'prisma/migrations',
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
@@ -468,7 +467,6 @@ export default defineConfig({
seed: `tsx prisma/seed.ts`,
//add-end
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
diff --git a/content/800-guides/170-react-router-7.mdx b/content/800-guides/170-react-router-7.mdx
index 6cd1474854..c953dd4990 100644
--- a/content/800-guides/170-react-router-7.mdx
+++ b/content/800-guides/170-react-router-7.mdx
@@ -129,7 +129,6 @@ export default defineConfig({
migrations: {
path: 'prisma/migrations',
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
@@ -209,7 +208,6 @@ export default defineConfig({
seed: `tsx prisma/seed.ts`,
//add-end
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
diff --git a/content/800-guides/180-solid-start.mdx b/content/800-guides/180-solid-start.mdx
index 705eaf4a58..85e99aeff7 100644
--- a/content/800-guides/180-solid-start.mdx
+++ b/content/800-guides/180-solid-start.mdx
@@ -149,7 +149,6 @@ export default defineConfig({
migrations: {
path: 'prisma/migrations',
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
@@ -230,7 +229,6 @@ export default defineConfig({
seed: `tsx prisma/seed.ts`,
//add-end
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
diff --git a/content/800-guides/190-data-dog.mdx b/content/800-guides/190-data-dog.mdx
index 41d7894df3..fcba863180 100644
--- a/content/800-guides/190-data-dog.mdx
+++ b/content/800-guides/190-data-dog.mdx
@@ -182,6 +182,35 @@ model Post {
//add-end
```
+Create a `prisma.config.ts` file to configure Prisma:
+
+```typescript file=prisma.config.ts
+//add-start
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+//add-end
+```
+
+:::note
+
+You'll need to install the `dotenv` package if you haven't already:
+
+```terminal
+npm install dotenv
+```
+
+:::
+
### 2.3. Generate the Prisma Client and run migrations
Generate the Prisma Client and apply your schema to your database:
diff --git a/content/800-guides/190-sveltekit.mdx b/content/800-guides/190-sveltekit.mdx
index 9031029e71..7625b273aa 100644
--- a/content/800-guides/190-sveltekit.mdx
+++ b/content/800-guides/190-sveltekit.mdx
@@ -143,7 +143,6 @@ export default defineConfig({
migrations: {
path: 'prisma/migrations',
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
@@ -223,7 +222,6 @@ export default defineConfig({
seed: `tsx prisma/seed.ts`,
//add-end
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
diff --git a/content/800-guides/200-clerk-nextjs.mdx b/content/800-guides/200-clerk-nextjs.mdx
index 4d4409fa5d..e1fcfd2810 100644
--- a/content/800-guides/200-clerk-nextjs.mdx
+++ b/content/800-guides/200-clerk-nextjs.mdx
@@ -286,6 +286,35 @@ model Post {
This will create two models: `User` and `Post`, with a one-to-many relationship between them.
+Create a `prisma.config.ts` file to configure Prisma:
+
+```typescript file=prisma.config.ts showLineNumbers
+//add-start
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+//add-end
+```
+
+:::note
+
+You'll need to install the `dotenv` package:
+
+```terminal
+npm install dotenv
+```
+
+:::
+
Now, run the following command to create the database tables and generate the Prisma Client:
```terminal
diff --git a/content/800-guides/210-shopify.mdx b/content/800-guides/210-shopify.mdx
index b8a9eca491..81c9e4afa9 100644
--- a/content/800-guides/210-shopify.mdx
+++ b/content/800-guides/210-shopify.mdx
@@ -85,6 +85,35 @@ model Session {
}
```
+Create a `prisma.config.ts` file to configure Prisma:
+
+```typescript file=prisma.config.ts
+//add-start
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+//add-end
+```
+
+:::note
+
+Since Shopify apps typically have dotenv pre-installed, you should already have access to it. If not, install it with:
+
+```terminal
+npm install dotenv
+```
+
+:::
+
To enable your app to store notes for each product, let's add a new `ProductNote` model to your Prisma schema.
This model will allow you to save and organize notes linked to individual products in your database through the `productGid` field.
diff --git a/content/800-guides/220-astro.mdx b/content/800-guides/220-astro.mdx
index ccd930ce0b..ad28d9a98c 100644
--- a/content/800-guides/220-astro.mdx
+++ b/content/800-guides/220-astro.mdx
@@ -130,7 +130,6 @@ export default defineConfig({
migrations: {
path: 'prisma/migrations',
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
@@ -223,7 +222,6 @@ export default defineConfig({
path: 'prisma/migrations',
seed: `tsx prisma/seed.ts`,
},
- engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
diff --git a/content/800-guides/230-betterauth-nextjs.mdx b/content/800-guides/230-betterauth-nextjs.mdx
index 5a048fb22c..7caaccb31d 100644
--- a/content/800-guides/230-betterauth-nextjs.mdx
+++ b/content/800-guides/230-betterauth-nextjs.mdx
@@ -1,8 +1,8 @@
---
-title: 'How to use Prisma ORM with Better-Auth and Next.js'
-metaTitle: 'How to use Prisma ORM and Prisma Postgres with Better-Auth and Next.js'
-description: 'Learn how to use Prisma ORM in a Next.js app with Better-Auth'
-sidebar_label: 'Better-Auth (with Next.js)'
+title: 'How to use Prisma ORM with Better Auth and Next.js'
+metaTitle: 'How to use Prisma ORM and Prisma Postgres with Better Auth and Next.js'
+description: 'Learn how to use Prisma ORM in a Next.js app with Better Auth'
+sidebar_label: 'Better Auth (with Next.js)'
image: '/img/guides/prisma-betterauth-nextjs-cover.png'
completion_time: '25 min'
community_section: true
@@ -10,9 +10,9 @@ community_section: true
## Introduction
-[Better-Auth](https://better-auth.com/) is a modern, open-source authentication solution for web applications. It's built with TypeScript, React, and Prisma to provide a simple and extensible auth experience.
+[Better Auth](https://better-auth.com/) is a modern, open-source authentication solution for web applications. It's built with TypeScript and provides a simple and extensible auth experience with support for multiple database adapters, including Prisma.
-In this guide, you'll wire Better-Auth into a brand-new [Next.js](https://nextjs.org/) app and persist users in a [Prisma Postgres](https://prisma.io/postgres) database. You can find a complete example of this guide on [GitHub](https://github.com/prisma/prisma-examples/tree/latest/orm/betterauth-nextjs).
+In this guide, you'll wire Better Auth into a brand-new [Next.js](https://nextjs.org/) app and persist users in a [Prisma Postgres](https://prisma.io/postgres) database. You can find a complete example of this guide on [GitHub](https://github.com/prisma/prisma-examples/tree/latest/orm/betterauth-nextjs).
## Prerequisites
@@ -78,17 +78,46 @@ Once installed, initialize Prisma in your project:
npx prisma init --db --output ../src/generated/prisma
```
:::info
-You'll need to answer a few questions while setting up your Prisma Postgres database. Select the region closest to your location and a memorable name for your database like "My Better-Auth Project"
+You'll need to answer a few questions while setting up your Prisma Postgres database. Select the region closest to your location and a memorable name for your database like "My Better Auth Project"
:::
This will create:
-- A `prisma` directory with a `schema.prisma` file.
-- A Prisma Postgres database.
-- A `.env` file containing the `DATABASE_URL` at the project root.
-- An `output` directory for the generated Prisma Client as `better-auth/generated/prisma`.
+- A `prisma` directory with a `schema.prisma` file
+- A Prisma Postgres database
+- A `.env` file containing the `DATABASE_URL` at the project root
+- An `output` directory for the generated Prisma Client as `better-auth/generated/prisma`
-### 2.2. Configure the Prisma client generator
+### 2.2. Configure Prisma
+
+Create a `prisma.config.ts` file in the root of your project with the following content:
+
+```typescript file=prisma.config.ts
+import 'dotenv/config'
+import { defineConfig, env } from 'prisma/config';
+
+export default defineConfig({
+ schema: 'prisma/schema.prisma',
+ migrations: {
+ path: 'prisma/migrations',
+ },
+ datasource: {
+ url: env('DATABASE_URL'),
+ },
+});
+```
+
+:::note
+
+The `dotenv` package should already be installed as it's a Next.js dependency. If not, install it using:
+
+```bash
+npm install dotenv
+```
+
+:::
+
+### 2.3. Generate the Prisma client
Run the following command to create the database tables and generate the Prisma Client:
@@ -96,9 +125,9 @@ Run the following command to create the database tables and generate the Prisma
npx prisma generate
```
-### 2.3. Set up a global Prisma client
+### 2.4. Set up a global Prisma client
-Create a `/lib` directory and a `prisma.ts` file inside it. This file will be used to create and export your Prisma Client instance.
+In the `src` directory, create a `lib` folder and a `prisma.ts` file inside it. This file will be used to create and export your Prisma Client instance.
```terminal
mkdir -p src/lib
@@ -149,19 +178,19 @@ We recommend using a connection pooler (like [Prisma Accelerate](https://www.pri
If you choose not to use one, **avoid** instantiating `PrismaClient` globally in long-lived environments. Instead, create and dispose of the client per request to prevent exhausting your database connections.
:::
-## 3. Set up Better-Auth
+## 3. Set up Better Auth
-Now it's time to integrate Better-Auth for authentication.
+Now it's time to integrate Better Auth for authentication.
-### 3.1. Install and configure Better-Auth
+### 3.1. Install and configure Better Auth
-First, install the Better-Auth core package:
+First, install the Better Auth core package:
```terminal
npm install better-auth
```
-Next, generate a secure secret that Better-Auth will use to sign authentication tokens. This ensures your tokens cannot be messed with.
+Next, generate a secure secret that Better Auth will use to sign authentication tokens. This ensures your tokens cannot be messed with.
```terminal
npx @better-auth/cli@latest secret
@@ -170,7 +199,7 @@ npx @better-auth/cli@latest secret
Copy the generated secret and add it, along with your application's URL, to your `.env` file:
```dotenv file=.env showLineNumbers
-# Better-Auth
+# Better Auth
//add-start
BETTER_AUTH_SECRET=your-generated-secret
BETTER_AUTH_URL=http://localhost:3000
@@ -180,13 +209,13 @@ BETTER_AUTH_URL=http://localhost:3000
DATABASE_URL="your-database-url"
```
-Now, create a configuration file for Better-Auth at `src/lib/auth.ts`:
+Now, create a configuration file for Better Auth. In the `src/lib` directory, create an `auth.ts` file:
```terminal
touch src/lib/auth.ts
```
-In this file, you'll configure Better-Auth to use the Prisma adapter, which allows it to persist user and session data in your database. You will also enable email and password authentication.
+In this file, you'll configure Better Auth to use the Prisma adapter, which allows it to persist user and session data in your database. You will also enable email and password authentication.
```ts file=src/lib/auth.ts
import { betterAuth } from 'better-auth'
@@ -200,7 +229,7 @@ export const auth = betterAuth({
})
```
-Better-Auth also supports other sign-in methods like social logins (Google, GitHub, etc.), which you can explore in their [documentation](https://www.better-auth.com/docs/authentication/email-password).
+Better Auth also supports other sign-in methods like social logins (Google, GitHub, etc.), which you can explore in their [documentation](https://www.better-auth.com/docs/authentication/email-password).
```ts file=src/lib/auth.ts
import { betterAuth } from 'better-auth'
@@ -240,9 +269,9 @@ export const auth = betterAuth({
```
:::
-### 3.2. Add Better-Auth models to your schema
+### 3.2. Add Better Auth models to your schema
-Better-Auth provides a CLI command to automatically add the necessary authentication models (`User`, `Session`, `Account`, and `Verification`) to your `schema.prisma` file.
+Better Auth provides a CLI command to automatically add the necessary authentication models (`User`, `Session`, `Account`, and `Verification`) to your `schema.prisma` file.
Run the following command:
@@ -325,20 +354,18 @@ With the new models in your schema, you need to update your database. Run a migr
npx prisma migrate dev --name add-auth-models
```
-
-
## 4. Set up the API routes
-Better-Auth needs an API endpoint to handle authentication requests like sign-in, sign-up, and sign-out. You'll create a catch-all API route in Next.js to handle all requests sent to `/api/auth/[...all]`.
+Better Auth needs an API endpoint to handle authentication requests like sign-in, sign-up, and sign-out. You'll create a catch-all API route in Next.js to handle all requests sent to `/api/auth/[...all]`.
-First, create the necessary directory and file:
+In the `src/app/api` directory, create an `auth/[...all]` folder structure and a `route.ts` file inside it:
```terminal
mkdir -p "src/app/api/auth/[...all]"
touch "src/app/api/auth/[...all]/route.ts"
```
-Add the following code to the newly created `route.ts` file. This code uses a helper from Better-Auth to create Next.js-compatible `GET` and `POST` request handlers.
+Add the following code to the newly created `route.ts` file. This code uses a helper from Better Auth to create Next.js-compatible `GET` and `POST` request handlers.
```ts
import { auth } from "@/lib/auth";
@@ -347,7 +374,7 @@ import { toNextJsHandler } from "better-auth/next-js";
export const { POST, GET } = toNextJsHandler(auth);
```
-Next, you'll need a client-side utility to interact with these endpoints from your React components. Create a new file `src/lib/auth-client.ts`:
+Next, you'll need a client-side utility to interact with these endpoints from your React components. In the `src/lib` directory, create an `auth-client.ts` file:
```terminal
touch src/lib/auth-client.ts
@@ -363,7 +390,11 @@ export const { signIn, signUp, signOut, useSession } = createAuthClient()
## 5. Set up your pages
-Now, let's build the user interface for authentication. Create the pages for signing up, signing in, and a protected dashboard:
+Now, let's build the user interface for authentication. In the `src/app` directory, create the following folder structure:
+
+- `sign-up/page.tsx`
+- `sign-in/page.tsx`
+- `dashboard/page.tsx`
```terminal
mkdir -p src/app/{sign-up,sign-in,dashboard}
@@ -410,7 +441,7 @@ export default function SignUpPage() {
}
```
-Now, import the `signUp` function from your Better-Auth client and add the `handleSubmit` function. This function is triggered on form submission and calls the `signUp.email` method provided by Better-Auth, passing the user's name, email, and password.
+Now, import the `signUp` function from your Better Auth client and add the `handleSubmit` function. This function is triggered on form submission and calls the `signUp.email` method provided by Better Auth, passing the user's name, email, and password.
```tsx file=src/app/sign-up/page.tsx
"use client";
@@ -611,7 +642,7 @@ export default function SignInPage() {
}
```
-Add the `handleSubmit` function, this time importing and using the `signIn.email` method from Better-Auth.
+Add the `handleSubmit` function, this time importing and using the `signIn.email` method from Better Auth.
```tsx file=src/app/sign-in/page.tsx
"use client";
@@ -778,7 +809,7 @@ export default function DashboardPage() {
}
```
-Import the `useSession` hook from your Better-Auth client. This hook is the key to managing authentication state on the client side. It provides the session data and a pending status.
+Import the `useSession` hook from your Better Auth client. This hook is the key to managing authentication state on the client side. It provides the session data and a pending status.
```tsx file=src/app/dashboard/page.tsx
"use client";
@@ -816,7 +847,7 @@ export default function DashboardPage() {
const router = useRouter();
const { data: session, isPending } = useSession();
- //add-start: redirect if not signed in
+ //add-start
useEffect(() => {
if (!isPending && !session?.user) {
router.push("/sign-in");
@@ -851,7 +882,7 @@ export default function DashboardPage() {
}
}, [isPending, session, router]);
- //add-start: loading and redirect states
+ //add-start
if (isPending)
return
Loading...
;
if (!session?.user)
@@ -890,7 +921,7 @@ export default function DashboardPage() {
if (!session?.user)
return
Redirecting...
;
- //add-start: destructure user from session
+ //add-start
const { user } = session;
//add-end
@@ -899,7 +930,7 @@ export default function DashboardPage() {