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
12 changes: 12 additions & 0 deletions content/800-guides/010-data-migration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ Generate the migration:
npx prisma migrate dev --name add-status-column
```

Then generate Prisma Client:

```bash
npx prisma generate
```

## 3. Migrate the data

### 3.1. Create migration script
Expand Down Expand Up @@ -237,6 +243,12 @@ Create and run the final migration:
npx prisma migrate dev --name drop-published-column
```

Then generate Prisma Client:

```bash
npx prisma generate
```

## 5. Deploy to production

### 5.1. Set up deployment
Expand Down
3 changes: 3 additions & 0 deletions content/800-guides/020-implementing-schema-changes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ And generates a migration:

```terminal
npx prisma migrate dev --name new-field
npx prisma generate
```

### 3.2. Developer B's changes
Expand All @@ -186,6 +187,7 @@ And generates a migration:

```terminal
npx prisma migrate dev --name new-model
npx prisma generate
```

### 3.3. Merge changes
Expand Down Expand Up @@ -224,6 +226,7 @@ Run the migrate command:

```terminal
npx prisma migrate dev
npx prisma generate
```

This will:
Expand Down
6 changes: 3 additions & 3 deletions content/800-guides/080-turborepo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Next, export the generated types and an instance of `PrismaClient` so it can use
In the `packages/database` directory, create a `src` folder and add a `client.ts` file. This file will define an instance of `PrismaClient`:

```ts file=packages/database/src/client.ts
import { PrismaClient } from "../generated/prisma";
import { PrismaClient } from "../generated/prisma/client";
import { PrismaPg } from '@prisma/adapter-pg';

const adapter = new PrismaPg({
Expand All @@ -384,8 +384,8 @@ if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
Then create an `index.ts` file in the `src` folder to re-export the generated prisma types and the `PrismaClient` instance:

```ts file=packages/database/src/index.ts
export { prisma } from './client' // exports instance of prisma
export * from "../generated/prisma" // exports generated types from prisma
export { prisma } from './client' // exports instance of prisma
export * from "../generated/prisma/client" // exports generated types from prisma
```

Follow the [Just-in-Time packaging pattern](https://turbo.build/repo/docs/core-concepts/internal-packages#just-in-time-packages) and create an entrypoint to the package inside `packages/database/package.json`:
Expand Down
15 changes: 11 additions & 4 deletions content/800-guides/090-nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,28 @@ export default defineConfig({
});
```

### 2.4. Configure the Prisma Client generator
### 2.4. Run migrations and generate Prisma Client

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

```terminal
npx prisma migrate dev --name init
```

Then generate Prisma Client:

```terminal
npx prisma generate
```

### 2.5. Seed the database

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
import { PrismaClient, Prisma } from "../app/generated/prisma";
import { PrismaClient, Prisma } from "../app/generated/prisma/client";
import { PrismaPg } from '@prisma/adapter-pg'
import 'dotenv/config'

Expand Down Expand Up @@ -285,7 +292,7 @@ Now, add the following code to your `lib/prisma.ts` file:

```typescript file=lib/prisma.ts showLineNumbers
//add-start
import { PrismaClient } from '../app/generated/prisma'
import { PrismaClient } from '../app/generated/prisma/client'
import { PrismaPg } from '@prisma/adapter-pg'

const globalForPrisma = global as unknown as {
Expand Down
10 changes: 8 additions & 2 deletions content/800-guides/130-docker.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Add the following code to set up a basic Express server:
```js file=index.js
//add-start
const express = require("express");
const { PrismaClient } = require("./generated/prisma_client");
const { PrismaClient } = require("./generated/prisma_client/client");
const { PrismaPg } = require("@prisma/adapter-pg");

const adapter = new PrismaPg({
Expand Down Expand Up @@ -286,7 +286,13 @@ Run the migration to create the database schema:
npx prisma migrate dev --name init
```

This should generate a `migrations` folder in the `prisma` folder.
Then generate Prisma Client:

```terminal
npx prisma generate
```

This should generate a `migrations` folder in the `prisma` folder and the Prisma Client in the `generated/prisma_client` directory.

### 2.4. Test the application

Expand Down
14 changes: 7 additions & 7 deletions content/800-guides/150-multiple-databases.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The `prisma@latest init --db` command:

- Connects your CLI to your [Prisma Data Platform](https://console.prisma.io) account. If you are not logged in or do not have an account, your browser will open to guide you through creating a new account or signing into your existing one.
- Creates a `prisma` directory containing a `schema.prisma` file for your database models.
- Creates a `.env` file with your `DATABASE_URL` (e.g., for Prisma Postgres it should have something similar to `DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI..."`).
- Creates a `.env` file with your `DATABASE_URL` (e.g., `DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"`).

Rename the `prisma` folder to `prisma-user-database`:

Expand All @@ -105,10 +105,10 @@ Edit your `.env` file to rename `DATABASE_URL` to `PPG_USER_DATABASE_URL`:

```text file=.env
//delete-start
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
//delete-end
//add-start
PPG_USER_DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
PPG_USER_DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
//add-end
```

Expand Down Expand Up @@ -184,10 +184,10 @@ Rename the `DATABASE_URL` variable in `.env` to `PPG_POST_DATABASE_URL`:

```text file=.env
//delete-start
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
//delete-end
//add-start
PPG_POST_DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=eyJhbGciOiJIUzI...
PPG_POST_DATABASE_URL="postgresql://user:password@host:5432/database?sslmode=require"
//add-end
```

Expand Down Expand Up @@ -287,7 +287,7 @@ In `lib/user-prisma-client.ts`, add the following code:

```ts file=lib/user-prisma-client.ts
//add-start
import { PrismaClient } from "../prisma-user-database/user-database-client-types";
import { PrismaClient } from "../prisma-user-database/user-database-client-types/client";
import { PrismaPg } from "@prisma/adapter-pg";

const adapter = new PrismaPg({
Expand Down Expand Up @@ -316,7 +316,7 @@ In `lib/post-prisma-client.ts`, add this code:

```ts file=lib/post-prisma-client.ts
//add-start
import { PrismaClient } from "../prisma-post-database/post-database-client-types";
import { PrismaClient } from "../prisma-post-database/post-database-client-types/client";
import { PrismaPg } from "@prisma/adapter-pg";

const adapter = new PrismaPg({
Expand Down
1 change: 1 addition & 0 deletions content/800-guides/160-tanstack-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ Now, run the following command to create the database tables and generate the Pr

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

Expand Down
1 change: 1 addition & 0 deletions content/800-guides/170-react-router-7.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Now, run the following command to create the database tables and generate the Pr

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

Expand Down
1 change: 1 addition & 0 deletions content/800-guides/180-solid-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Now, run the following command to create the database tables and generate the Pr

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

Expand Down
48 changes: 7 additions & 41 deletions content/800-guides/190-data-dog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,7 @@ Run the following commands to install Prisma and a minimal TypeScript runner:
npm install -D prisma tsx
```

Then initialize Prisma:

:::note

You can use the `--db` flag to create a [new Prisma Postgres](/postgres) instance when initializing Prisma in your project.

:::

<TabbedContent code>
<TabItem value="Prisma Postgres (recommended)">

<br />
Then initialize Prisma with the `--db` flag to create a [new Prisma Postgres](/postgres) instance:

```terminal
npx prisma init --db --output ../src/generated/prisma
Expand All @@ -102,43 +91,20 @@ npx prisma init --db --output ../src/generated/prisma
You will be prompted to name your database and select the closest region. For clarity, choose a memorable name (e.g., `My Datadog Project`).

:::
</TabItem>
<TabItem value="Your own database">

```terminal
npx prisma init --output ../src/generated/prisma
```

</TabItem>
</TabbedContent>


This command does the following:

- Creates a `prisma` directory with a `schema.prisma` file.
- Creates a `prisma` directory with a `schema.prisma` file.
- Generates the Prisma Client in the `/src/generated/prisma` directory (as specified in the `--output` flag).
- Creates a `.env` file at the project root with your database connection string (`DATABASE_URL`).
- Creates a `.env` file at the project root with your database connection string (`DATABASE_URL`).

If you did not use the `--db` flag, replace the placeholder database URL in the `.env` file:

<TabbedContent code>
<TabItem value="Prisma Postgres">
The `.env` file should contain a standard connection string:

```bash file=.env
DATABASE_URL="prisma+postgres://accelerate.prisma-data.net/?api_key=..."
# Placeholder url you have to replace
DATABASE_URL="postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample"
```

</TabItem>
<TabItem value="Your own database">

```bash file=.env
# Placeholder url you have to replace
DATABASE_URL="postgresql://janedoe:mypassword@localhost:5432/mydb?schema=sample"
```

</TabItem>
</TabbedContent>

Install the driver adapter for PostgreSQL:

```terminal
Expand Down Expand Up @@ -289,7 +255,7 @@ Create a `src/client.ts` to hold your Prisma Client instantiation:

```ts file=src/client.ts
import { tracer } from "./tracer";
import { PrismaClient } from "./generated/prisma";
import { PrismaClient } from "./generated/prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";

const adapter = new PrismaPg({
Expand Down
1 change: 1 addition & 0 deletions content/800-guides/190-sveltekit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Now, run the following command to create the database tables and generate the Pr

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

Expand Down
3 changes: 2 additions & 1 deletion content/800-guides/200-clerk-nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ Now, run the following command to create the database tables and generate the Pr

```terminal
npx prisma migrate dev --name init
npx prisma generate
```

:::warning
Expand All @@ -327,7 +328,7 @@ In the root directory, create a `lib` directory and a `prisma.ts` file inside it

```tsx file=lib/prisma.ts showLineNumbers
//add-start
import { PrismaClient } from "../app/generated/prisma";
import { PrismaClient } from "../app/generated/prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";

const adapter = new PrismaPg({
Expand Down
Loading
Loading