Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion content/800-guides/080-turborepo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ Inside the `database` directory, initialize prisma by running:
This will create several files inside `packages/database`:

- A `prisma` directory with a `schema.prisma` file.
- A `prisma.config.ts` file for configuring Prisma
- A Prisma Postgres database.
- A `.env` file containing the `DATABASE_URL` at the project root.
- An `output` directory for the generated Prisma Client as `generated/prisma`.
Expand All @@ -193,7 +194,7 @@ In the `packages/database/prisma/schema.prisma` file, add the following models:

```prisma file=packages/database/prisma/schema.prisma
generator client {
provider = "prisma-client-js"
provider = "prisma-client"
output = "../generated/prisma"
}

Expand Down
88 changes: 45 additions & 43 deletions content/800-guides/090-nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ To get started with Prisma, you'll need to install a few dependencies:
<TabItem value="Prisma Postgres (recommended)">
```terminal
npm install prisma tsx --save-dev
npm install @prisma/extension-accelerate @prisma/client
npm install @prisma/extension-accelerate @prisma/client dotenv
```
</TabItem>
<TabItem value="Other databases">
```terminal
npm install prisma tsx --save-dev
npm install @prisma/client
npm install @prisma/client dotenv
```
</TabItem>
</TabbedContent>
Expand All @@ -93,6 +93,7 @@ You'll need to answer a few questions while setting up your Prisma Postgres data
This will create:

- A `prisma` directory with a `schema.prisma` file.
- A `prisma.config.ts` file for configuring Prisma
- A Prisma Postgres database.
- A `.env` file containing the `DATABASE_URL` at the project root.
- An `output` directory for the generated Prisma Client as `app/generated/prisma`.
Expand All @@ -103,7 +104,7 @@ In the `prisma/schema.prisma` file, add the following models:

```prisma file=prisma/schema.prisma
generator client {
provider = "prisma-client-js"
provider = "prisma-client"
output = "../app/generated/prisma"
}

Expand Down Expand Up @@ -133,14 +134,36 @@ model Post {

This creates two models: `User` and `Post`, with a one-to-many relationship between them.

### 2.3. Configure the Prisma Client generator
### 2.3 Add `dotenv` to `prisma.config.ts`

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
//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'),
},
});
```

### 2.4. Configure the Prisma Client generator

Now, run the following command to create the database tables and generate the Prisma Client:

```terminal
npx prisma migrate dev --name init
```
### 2.4. Seed the database
### 2.5. Seed the database

Add some seed data to populate the database with sample users and posts.

Expand Down Expand Up @@ -193,45 +216,24 @@ export async function main() {
main();
```

Now, tell Prisma how to run this script by updating your `package.json`:

```json file=package.json
{
"name": "nextjs-prisma",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint"
Now, tell Prisma how to run this script by updating your `prisma.config.ts`:

```ts file=prisma.config.ts
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config';
export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: {
path: 'prisma/migrations',
//add-start
seed: `tsx prisma/seed.ts`,
//add-end
},
// add-start
"prisma": {
"seed": "tsx prisma/seed.ts"
engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
// add-end
"dependencies": {
"@prisma/client": "^6.7.0",
"@prisma/extension-accelerate": "^1.3.0",
"next": "15.3.1",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "15.3.1",
"prisma": "^6.7.0",
"tailwindcss": "^4",
"tsx": "^4.19.4",
"typescript": "^5"
}
}
});
```


Expand Down Expand Up @@ -266,7 +268,7 @@ And open Prisma Studio to inspect your data:
npx prisma studio
```

### 2.5 Set up Prisma Client
### 2.6 Set up Prisma Client

Now that you have a database with some initial data, you can set up Prisma Client and connect it to your database.

Expand Down
63 changes: 43 additions & 20 deletions content/800-guides/160-tanstack-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ To get started with Prisma, you'll need to install a few dependencies:
<TabItem value="Prisma Postgres (recommended)">
```terminal
npm install prisma tsx --save-dev
npm install @prisma/extension-accelerate @prisma/client
npm install @prisma/extension-accelerate @prisma/client dotenv
```
</TabItem>
<TabItem value="Other databases">
```terminal
npm install prisma tsx --save-dev
npm install @prisma/client
npm install @prisma/client dotenv
```
</TabItem>
</TabbedContent>
Expand All @@ -334,6 +334,7 @@ You'll need to answer a few questions while setting up your Prisma Postgres data
This will create:

- A `prisma` directory with a `schema.prisma` file.
- A `prisma.config.ts` file for configuring Prisma
- A Prisma Postgres database.
- A `.env` file containing the `DATABASE_URL` at the project root.
- An `output` directory for the generated Prisma Client as `app/generated/prisma`.
Expand All @@ -344,7 +345,6 @@ In `schema.prisma`, create a model for our posts and change the generator to use

```prisma file=prisma/schema.prisma
generator client {
//edit-next-line
provider = "prisma-client"
output = "../app/generated/prisma"
}
Expand Down Expand Up @@ -375,27 +375,46 @@ model Post {

This creates two models: `User` and `Post`, with a one-to-many relationship between them.

### 2.3. Configure the Prisma Client generator
### 2.3 Add `dotenv` to `prisma.config.ts`

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
//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'),
},
});
```

### 2.4. Configure the Prisma Client generator

Now, run the following command to create the database tables and generate the Prisma Client:

```terminal
npx prisma migrate dev --name init
```
### 2.4. Seed the database
### 2.5. Seed the database

Let's add some seed data to populate the database with sample users and posts.

Create a new file called `seed.ts` in the `prisma/` directory:

```typescript file=prisma/seed.ts
//add-next-line
import { PrismaClient, Prisma } from "../src/generated/prisma/client.js";
import { PrismaClient, Prisma } from "../app/generated/prisma/client.js";

//add-next-line
const prisma = new PrismaClient();

//add-start
const userData: Prisma.UserCreateInput[] = [
{
name: "Alice",
Expand Down Expand Up @@ -428,28 +447,32 @@ const userData: Prisma.UserCreateInput[] = [
},
},
];
//add-end

//add-start
export async function main() {
for (const u of userData) {
await prisma.user.create({ data: u });
}
}
//add-end

//add-next-line
main();
```

Now, tell Prisma how to run this script by updating your `package.json`:
Now, tell Prisma how to run this script by updating your `prisma.config.ts`:

```json file=package.json
```ts file=prisma.config.ts
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config';
export default defineConfig({
schema: 'prisma/schema.prisma',
migrations: {
path: 'prisma/migrations',
//add-start
"prisma": {
"seed": "tsx prisma/seed.ts"
}
seed: `tsx prisma/seed.ts`,
//add-end
},
engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
});
```

Run the seed script:
Expand Down
Loading
Loading