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
2 changes: 1 addition & 1 deletion apps/docs/content/docs/(index)/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metaDescription: 'Build data-driven applications with ease using Prisma ORM, add
[**Prisma ORM**](/orm) is an open-source ORM that provides fast, type-safe access to Postgres, MySQL, SQLite, and other databases, and runs smoothly across Node.js, Bun, and Deno.

```npm
npx prisma init --db
npx prisma init
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Update `package.json` to enable ESM:
}
```

## 4. Initialize Prisma ORM and create a Prisma Postgres database
## 4. Initialize Prisma ORM

You can now invoke the Prisma CLI by prefixing it with `npx`:

Expand All @@ -79,21 +79,14 @@ npx prisma
Next, set up your Prisma ORM project by creating your [Prisma Schema](/orm/prisma-schema/overview) file with the following command:

```npm
npx prisma init --db --output ../generated/prisma
npx prisma init --output ../generated/prisma
```

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.

:::tip[Using local Prisma Postgres]

If you want to use a local Prisma Postgres database instead of a cloud database, you can skip the `--db` flag and start a local Prisma Postgres instance by running `npx prisma dev`. For more details, see the [local Prisma Postgres documentation](/postgres/database/local-development#setting-up-local-development-for-prisma-postgres).

:::
`prisma init` creates the Prisma scaffolding and a local `DATABASE_URL`.

This command does a few things:

- Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models
- Creates a new Prisma Postgres database (when using `--db` flag)
- Creates a `.env` file in the root directory for environment variables
- Creates a `prisma.config.ts` file for Prisma configuration

Expand Down Expand Up @@ -127,6 +120,12 @@ datasource db {
}
```

Create a Prisma Postgres database and replace the generated `DATABASE_URL` in your `.env` file with the `postgres://...` connection string from the CLI output:

```npm
npx create-db
```

## 5. Define your data model

Open `prisma/schema.prisma` and add the following models:
Expand Down
16 changes: 8 additions & 8 deletions apps/docs/content/docs/(index)/prisma-postgres/from-the-cli.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@ metaTitle: From the CLI
metaDescription: Start building a Prisma application with a Prisma Postgres database from the CLI
---

This page provides a step-by-step guide for Prisma Postgres after setting it up with `prisma init --db`:
This page provides a step-by-step guide for Prisma Postgres after setting it up with `prisma init` and `npx create-db`:

1. Set up a TypeScript app with Prisma ORM
1. Migrate the schema of your database
1. Query your database from TypeScript

## Prerequisites

This guide assumes you set up [Prisma Postgres](/postgres) instance with `prisma init --db`:
This guide assumes you initialized Prisma with `prisma init` and created a Prisma Postgres database with `npx create-db`:

```npm
npx prisma@latest init --db
npx prisma@latest init
npx create-db
```


Once this command has terminated:
Once these commands have terminated:

- You're logged into Prisma Data Platform.
- A new Prisma Postgres instance was created.
- The `prisma/` folder was created with an empty `schema.prisma` file.
- The `DATABASE_URL` env var was set in a `.env` file.
- The `prisma.config.ts` file was created with the default configuration.
- You have a Prisma Postgres connection string to paste into `.env`.

## 1. Organize your project directory

:::note

If you ran the `prisma init --db` command inside a folder where you want your project to live, you can skip this step and [proceed to the next section](/prisma-postgres/from-the-cli#2-set-up-your-project).
If you ran the `prisma init` command inside a folder where you want your project to live, you can skip this step and [proceed to the next section](/prisma-postgres/from-the-cli#2-set-up-your-project).

:::

Expand Down Expand Up @@ -122,7 +122,7 @@ Here's what each package does:

### 2.4. Review the generated prisma.config.ts

The `prisma init --db` command automatically created a `prisma.config.ts` file that looks like this:
The `prisma init` command automatically created a `prisma.config.ts` file that looks like this:

```typescript title="prisma.config.ts"
import "dotenv/config";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,23 @@ Update `package.json` to enable ESM:
}
```

## 4. Initialize Prisma ORM and create a Prisma Postgres database
## 4. Initialize Prisma ORM

Next, set up your Prisma ORM project by creating your [Prisma Schema](/orm/prisma-schema/overview) file with the following command:

```npm
npx prisma init --db --output ../generated/prisma
npx prisma init --output ../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.
`prisma init` creates the Prisma scaffolding and a local `DATABASE_URL`. In the next step, replace that value with a direct `postgres://...` connection string from Prisma Postgres.

:::

This command does a few things:

- Creates a `prisma/` directory with a `schema.prisma` file containing your database connection and schema models
- Creates a new Prisma Postgres database (when using `--db` flag)
- Creates a `.env` file in the root directory for environment variables
- Generates the Prisma Client in the `generated/prisma/` directory
- Creates a `prisma.config.ts` file for Prisma configuration
Expand Down Expand Up @@ -105,6 +104,12 @@ datasource db {
}
```

Create a Prisma Postgres database and replace the generated `DATABASE_URL` in your `.env` file with the `postgres://...` connection string from the CLI output:

```npm
npx create-db
```

## 5. Define your data model

Open `prisma/schema.prisma` and add the following models:
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/content/docs/ai/prompts/astro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default prisma
5. You MUST wrap all database calls in try-catch blocks
6. You MUST import from `'../generated/prisma/client'` (not `'@prisma/client'`)
7. You MUST use `import.meta.env.DATABASE_URL` in Astro (not `process.env`)
8. You MUST ALWAYS use the full `npx prisma init` command with ALL flags: `npx prisma init --db --output ../src/generated/prisma --generator-provider prisma-client`
8. You MUST use `npx prisma init --output ../src/generated/prisma` before editing the Prisma schema. If you need Prisma Postgres, run `npx create-db` and update `.env` with the returned `postgres://...` value

## CORRECT INSTALLATION

Expand All @@ -97,7 +97,7 @@ npm install @prisma/extension-accelerate @prisma/client
## CORRECT PRISMA INITIALIZATION

```npm
npx prisma init --db --output ../src/generated/prisma
npx prisma init --output ../src/generated/prisma
```

## CORRECT SCHEMA CONFIGURATION
Expand Down
58 changes: 26 additions & 32 deletions apps/docs/content/docs/ai/prompts/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default prisma
10. You MUST create a test script at `scripts/test-database.ts` to verify setup
11. You MUST NOT include `url` in the datasource block of `schema.prisma`
12. You MUST NOT include `engine` property in `prisma.config.ts`
13. You MUST use `npx prisma init --db --output ../app/generated/prisma` to create a real cloud database
13. You MUST use `npx prisma init --output ../app/generated/prisma` to scaffold Prisma, then `npx create-db` to create a real cloud database
14. You MUST use standard TCP URLs (`postgres://...`) in .env
15. You MUST NOT use `accelerateUrl` or `withAccelerate`

Expand All @@ -186,37 +186,35 @@ npm install @prisma/adapter-pg @prisma/client dotenv

## CORRECT PRISMA INITIALIZATION

> **FOR AI ASSISTANTS**: This command is **interactive** and requires user input. You **MUST ask the user to run this command manually** in their own terminal, then **wait for them to confirm completion** before proceeding with the next steps. Do NOT attempt to run this command yourself.
> **FOR AI ASSISTANTS**: `npx prisma init` is not interactive. Run it yourself if your environment allows it. If you need a real Prisma Postgres database, either run `npx create-db` or ask the user to run it and update `DATABASE_URL` before you continue.

```bash
# Initialize Prisma AND create a real Prisma Postgres cloud database
npx prisma init --db --output ../app/generated/prisma
# Initialize Prisma and scaffold the Prisma files
npx prisma init --output ../app/generated/prisma

# Then create a Prisma Postgres database
npx create-db
```

This command:
This step:

- Authenticates you with Prisma Console (if needed)
- Prompts for **region** and **project name**
- **Creates a cloud Prisma Postgres database**
- Generates:
- `prisma/schema.prisma` (with correct output path)
- `prisma.config.ts` (with dotenv import)
- **`.env` with a `DATABASE_URL`**
- Generates `prisma/schema.prisma` with the correct output path
- Generates `prisma.config.ts`
- Generates `.env` with a local `DATABASE_URL`
- Requires `npx create-db` if you want a real Prisma Postgres database

**IMPORTANT**: Ensure the generated `.env` uses a `postgres://` URL scheme. If it generates `prisma+postgres://`, replace it with the standard TCP connection string available in the Prisma Console.
**IMPORTANT**: After `npx create-db`, replace the generated `DATABASE_URL` in `.env` with the returned `postgres://...` connection string.

```text
DATABASE_URL="postgres://..."
```

**IMPORTANT**: Do NOT use `npx prisma init` without `--db` as this only creates local files without a database.

## CORRECT PRISMA CONFIG (prisma.config.ts)

When using `npx prisma init --db`, the `prisma.config.ts` is **auto-generated** with the correct configuration:
When using `npx prisma init`, the `prisma.config.ts` is **auto-generated** with the correct configuration:

```typescript
import "dotenv/config"; // ✅ Auto-included by prisma init --db
import "dotenv/config"; // ✅ Auto-included by prisma init
import { defineConfig, env } from "prisma/config";

export default defineConfig({
Expand Down Expand Up @@ -447,30 +445,26 @@ User should follow these steps (AI should provide these instructions):
npm install @prisma/adapter-pg @prisma/client dotenv
```

2. **Initialize Prisma AND create Prisma Postgres database** (⚠️ USER MUST RUN MANUALLY):
2. **Initialize Prisma, then create Prisma Postgres:**

> **AI ASSISTANT**: Ask the user to run this command in their own terminal. This is interactive and requires user input. Wait for the user to confirm completion before continuing.
> **AI ASSISTANT**: You can run `npx prisma init` yourself. If you should not provision cloud resources automatically, ask the user to run `npx create-db` and update `DATABASE_URL` before continuing.

```npm
npx prisma init --db --output ../app/generated/prisma
npx prisma init --output ../app/generated/prisma
npx create-db
```

The user should follow the terminal prompts to:
- Authenticate with Prisma Console (if needed)
- Choose a region (e.g., us-east-1)
- Name your project

Once complete, this creates `prisma/schema.prisma`, `prisma.config.ts`, AND `.env` with the `DATABASE_URL`.
This creates `prisma/schema.prisma`, `prisma.config.ts`, and `.env`, then returns a `postgres://...` connection string for Prisma Postgres.

**User should confirm when done** so the AI can proceed with the next steps.
**If you asked the user to run `npx create-db`, wait for them to share or paste the returned connection string before proceeding.**

3. **Verify `.env` was created** - Ensure `DATABASE_URL` uses `postgres://`. If it uses `prisma+postgres://`, change it to the TCP connection string.
3. **Verify `.env` was created** - Replace the generated `DATABASE_URL` with the `postgres://...` connection string returned by `npx create-db`.

```text
DATABASE_URL="postgres://..."
```

**Do NOT invent or manually change this URL. Use the one from Prisma Console.**
**Do NOT invent this URL. Use the one returned by `npx create-db`.**

4. **Update `prisma/schema.prisma`** - Add the User model (generator and datasource are already configured):

Expand Down Expand Up @@ -529,7 +523,7 @@ Before generating any code, you MUST verify:
10. Did you add `db:test` and `db:studio` scripts to package.json? If not, STOP and FIX.
11. Did you remove `url` from the datasource block in `schema.prisma`? If not, STOP and FIX.
12. Did you remove `engine` property from `prisma.config.ts`? If not, STOP and FIX.
13. Are you using `npx prisma init --db` (not just `npx prisma init`)? If not, STOP and FIX.
13. Did you run `npx prisma init` with the documented output path? If not, STOP and FIX.
14. Is the DATABASE_URL a TCP URL (`postgres://...`)? If it's a `prisma+postgres://` URL, STOP and FIX.
15. Did Prisma generate the `.env` file? If you invented the URL manually, STOP and FIX.

Expand Down Expand Up @@ -630,8 +624,8 @@ When asked about Prisma + Next.js implementation, you MUST:
11. ALWAYS use `@prisma/adapter-pg` and `adapter` property
12. NEVER include `url` in the datasource block of schema.prisma
13. NEVER include `engine` property in prisma.config.ts
14. ALWAYS ask the user to run `npx prisma init --db --output ../app/generated/prisma` **manually in their own terminal** (this command is interactive and requires user input for region and project name)
15. ALWAYS wait for user confirmation after they run the interactive `prisma init --db` command before proceeding
14. ALWAYS run `npx prisma init --output ../app/generated/prisma` before editing Prisma files. If you cannot provision cloud resources automatically, ask the user to run `npx create-db` and update `DATABASE_URL` before continuing
15. ALWAYS wait for user confirmation after they run `npx create-db` and share or apply the returned `postgres://...` connection string before proceeding
16. NEVER attempt to run interactive commands yourself - ask the user to do it
17. NEVER use `prisma+postgres://` URLs - ONLY `postgres://` TCP URLs
18. NEVER manually invent or fabricate DATABASE_URL values
Expand Down
Loading
Loading