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
127 changes: 100 additions & 27 deletions content/200-orm/500-reference/325-prisma-config-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,22 @@ You can define your config in either of two ways:
- Using the `defineConfig` helper:
```ts
import path from "node:path";
import { defineConfig } from "prisma/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
schema: path.join("prisma", "schema.prisma"),
migrations: {
migrations: {
path: path.join("db", "migrations"),
},
views: {
views: {
path: path.join("db", "views"),
},
typedSql: {
path: path.join("db", "queries"),
typedSql: {
path: path.join("db", "queries"),
},
engine: "classic",
datasource: {
url: env("DATABASE_URL")
}
});
```
Expand All @@ -45,6 +49,10 @@ You can define your config in either of two ways:
},
typedSql: {
path: path.join("db", "queries"),
},
engine: "classic",
datasource: {
url: env("DATABASE_URL")
}
} satisfies PrismaConfig;
```
Expand Down Expand Up @@ -90,6 +98,8 @@ export declare type PrismaConfig = {
typedSql?: {
path: string;
};
// Depending on the choice, you must provide either a `datasource` object or driver adapter
engine: 'classic' | 'js'

};
```
Expand Down Expand Up @@ -131,9 +141,6 @@ import path from "node:path";
import type { PrismaConfig } from "prisma";
import { PrismaD1 } from "@prisma/adapter-d1";

// import your .env file
import "dotenv/config";

export default {
experimental: {
adapter: true
Expand Down Expand Up @@ -332,6 +339,55 @@ Failed to load config file "~" as a TypeScript/JavaScript module. Error: Error:

:::


### `engine`

Configure the schema engine your project should use.

| Property | Type | Required | Default |
| -------- | ------------------ | -------- | ----------------- |
| `engine` | `classic` or `js` | No | `classic` |

By default it is set to use the classic engine, which requires that `datasource` be set
in your `prisma.config.ts`.

```ts
import path from "node:path";
import { defineConfig, env } from "prisma/config";
export default defineConfig({
engine: "classic",
datasource: {
url: env('DATABASE_URL'),
},
schema: path.join("prisma", "schema.prisma"),
});
```

Alternatively, if you are opting to use the newer Rust-free schema engine, set the engine to `js` and
provide the adapter you wish to use

```ts
import path from "node:path";
import { defineConfig, env } from "prisma/config";
import { PrismaD1 } from "@prisma/adapter-d1";
export default defineConfig({
experimental: {
adapter: true
},
engine: "js",
async adapter() {
return new PrismaD1({
CLOUDFLARE_D1_TOKEN: process.env.CLOUDFLARE_D1_TOKEN,
CLOUDFLARE_ACCOUNT_ID: process.env.CLOUDFLARE_ACCOUNT_ID,
CLOUDFLARE_DATABASE_ID: process.env.CLOUDFLARE_DATABASE_ID,
});
},
schema: path.join("prisma", "schema.prisma"),
});

```


## Common patterns

### Setting up your project
Expand All @@ -356,27 +412,37 @@ export default {} satisfies PrismaConfig;

### Using environment variables

When using `prisma.config.ts`, environment variables from `.env` files are not automatically loaded. If you're using node or deno, you'll need to:
When using `prisma.config.ts`, environment variables from `.env` files are not automatically loaded. Using `tsx`, you can pass a `--env-file` flag and that will automatically add those values to `process.env`

1. Pass a `--env-file` flag to the command line
If using Node or Deno:

<TabbedContent code>
<TabItem value="Node">
```terminal
node --env-file=.env index.js
node --env-file=.env --env-file=.local.env index.js
tsx --env-file=.env src/index.ts
tsx watch --env-file=.env --env-file=.local.env src/index.ts
tsx --env-file=.env ./prisma/seed.ts
```
</TabItem>
<TabItem value="Deno">
```terminal
deno run --env-file main.ts
deno run --env-file=.env --env-file=.local.env main.ts
```
</TabItem>
</TabbedContent>

For Bun, `.env` files are automatically loaded.

For accessing environment variables within `prisma.config.ts`, use the `env()` helper function to
provide a type-safe way of accessing that variable:

```tsx
import path from "node:path";
import { defineConfig, env } from "prisma/config";

type Env = {
DATABASE_URL: string
}
export default defineConfig({
engine: "classic",
datasource: {
url: env<Env>('DATABASE_URL'),
},
schema: path.join("prisma", "schema.prisma"),
});
```

For releases of Node before v20, you'll need to:

1. Install the `dotenv` package:
Expand All @@ -389,11 +455,18 @@ npm install dotenv

```ts
import "dotenv/config";
import type { PrismaConfig } from "prisma";
import { defineConfig, env } from "prisma/config";

export default {
// now you can use process.env variables
} satisfies PrismaConfig;
type Env = {
DATABASE_URL: string
}
export default defineConfig({
engine: "classic",
datasource: {
url: env<Env>('DATABASE_URL'),
},
schema: path.join("prisma", "schema.prisma"),
});
```

### Using multi-file schemas
Expand Down Expand Up @@ -496,7 +569,7 @@ If Prisma is installed globally (`npm i -g prisma`), it may not find your `prism
To avoid issues:

- Prefer local Prisma installations in your project.
- Or use `@prisma/config` locally and pass `--config` to point to your config file.
- Or use `prisma/config` locally and pass `--config` to point to your config file.

### Monorepos

Expand Down
9 changes: 9 additions & 0 deletions content/250-postgres/100-introduction/250-overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ You can view the following usage metrics in your Console Dashboard:
- Cumulative operations
- Operations per day

For details into individual databases in your workspace, each database has it's own metrics report
as well. You can view the following:

- Average response size
- Average query duration
- Total egress
- Total operations
- Cache utilization

## Billing

### Usage-based pricing
Expand Down
11 changes: 11 additions & 0 deletions content/500-platform/10-about.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ In each workspace, you can:
- invite other users to collaborate in the workspace.
- access the [Optimize dashboard](https://console.prisma.io/optimize?utm_source=docs&utm_medium=optimize-docs) to measure query performance and receive AI-powered recommendations.

### Database Metrics

You can have a single workspace that hosts several database. Within each database, you can view
detailed reports on how your database is performing, with various metrics like:

- Average response size
- Average query duration
- Total egress
- Total operations
- Cache utilization

#### Optimize

You can access Optimize within your [Prisma Data Platform account](https://console.prisma.io/optimize) workspace.
Expand Down
Loading