Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 30 additions & 1 deletion content/800-guides/010-data-migration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
29 changes: 29 additions & 0 deletions content/800-guides/020-implementing-schema-changes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions content/800-guides/030-migrate-from-typeorm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions content/800-guides/040-migrate-from-sequelize.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions content/800-guides/050-migrate-from-mongoose.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 32 additions & 3 deletions content/800-guides/060-migrate-from-drizzle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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).

Expand Down Expand Up @@ -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).

Expand Down
8 changes: 7 additions & 1 deletion content/800-guides/070-cloudflare-d1.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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!,
Expand Down
25 changes: 21 additions & 4 deletions content/800-guides/080-turborepo.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

</TabItem>
Expand All @@ -103,7 +103,7 @@ npm install @prisma/client

```terminal
yarn add prisma --dev
yarn add @prisma/client
yarn add @prisma/client dotenv
```

</TabItem>
Expand All @@ -112,7 +112,7 @@ yarn add @prisma/client

```terminal
pnpm add prisma --save-dev
pnpm add @prisma/client
pnpm add @prisma/client dotenv
```

</TabItem>
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -335,7 +352,7 @@ Navigate to the project root and run the following command to automatically migr
</TabbedContent>


Generate your `prisma.schema`
Generate your `schema.prisma`

To generate the types from Prisma schema, from the project root run:

Expand Down
8 changes: 4 additions & 4 deletions content/800-guides/090-nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
},
Expand Down Expand Up @@ -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: {
Expand All @@ -229,7 +230,6 @@ export default defineConfig({
seed: `tsx prisma/seed.ts`,
//add-end
},
engine: 'classic',
datasource: {
url: env('DATABASE_URL'),
},
Expand Down
Loading
Loading