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
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ If your previous up migration failed, you can apply your down migration on your

To apply the down migration on your production database after a failed up migration:

1. Use `db execute` to run your `down.sql` file on the database server:
1. Use `db execute` to run your `down.sql` file on the database server (using the database URL configured in `prisma.config.ts`):

```terminal
npx prisma db execute --file ./down.sql --schema prisma/schema.prisma
npx prisma db execute --file ./down.sql
```

2. Use `migrate resolve` to record that you rolled back the up migration named `add_profile`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ The following example demonstrates how to manually complete the steps of a migra

## Fixing failed migrations with `migrate diff` and `db execute`

:::info

**Prisma 7 note**: The `--url` flag has been removed from `prisma db execute`. To run these commands against a production database, you'll need to configure the production database URL in your `prisma.config.ts` file before running `db execute`. You can create a separate config file for production (e.g., `prisma.config.prod.ts`) and use `--config prisma.config.prod.ts` to specify it.

:::

To help with fixing a failed migration, Prisma ORM provides the following commands for creating and executing a migration file:

- [`prisma migrate diff`](/orm/reference/prisma-cli-reference#migrate-diff) which diffs two database schema sources to create a migration taking one to the state of the second. You can output either a summary of the difference or a sql script. The script can be output into a file via `> file_name.sql` or be piped to the `db execute --stdin` command.
Expand Down Expand Up @@ -200,7 +206,11 @@ In this case, you need to create a migration that takes your production database
- Run the following `prisma db execute` command:

```bash
npx prisma db execute --url "$DATABASE_URL_PROD" --file backward.sql
# Prisma 6
npx prisma db execute --url "$DATABASE_URL_PROD" --file backward.sql

# Prisma 7 (with production config)
npx prisma db execute --config prisma.config.prod.ts --file backward.sql
```

This applies the changes in the SQL script against the target database without interacting with the migrations table.
Expand Down Expand Up @@ -235,7 +245,11 @@ In this case, you need to fix the non-unique data and then go ahead with the res
- Run the following `prisma db execute` command:

```bash
# Prisma 6
npx prisma db execute --url "$DATABASE_URL_PROD" --file forward.sql

# Prisma 7 (with production config)
npx prisma db execute --config prisma.config.prod.ts --file forward.sql
```

This applies the changes in the SQL script against the target database without interacting with the migrations table.
Expand Down
40 changes: 16 additions & 24 deletions content/200-orm/500-reference/200-prisma-cli-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1266,10 +1266,7 @@ This command is currently not supported on [MongoDB](/orm/overview/databases/mon

:::

This command applies a SQL script to the database without interacting with the Prisma migrations table. The script takes two inputs:

- the SQL script, which can be provided either on standard input or in a file
- the data source, which can either be the URL of the data source or the path to your Prisma schema file
This command applies a SQL script to the database without interacting with the Prisma migrations table. The datasource URL configuration is read from the Prisma config file (e.g., `prisma.config.ts`).

The output of the command is connector-specific, and is not meant for returning data, but only to report success or failure.

Expand All @@ -1279,7 +1276,7 @@ See also:

#### Prerequisites

Before using the `db execute` command, if you do not use the `--url` option you must configure your database connection in your `prisma.config.ts` file.
Before using the `db execute` command, you must configure your database connection in your `prisma.config.ts` file.

For example:

Expand Down Expand Up @@ -1312,38 +1309,33 @@ export default defineConfig({

#### Options

One of the following data source inputs is required:
| Options | Required | Description |
| :--------- | :------- | :-------------------------------------------------------------------- |
| `--file` | Yes* | Path to a file. The content will be sent as the script to be executed |
| `--stdin` | No | Use the terminal standard input as the script to be executed |
| `--config` | No | Custom path to your Prisma config file |
| `--help` | No | Displays the help message |

| Options | Description |
| :--------- | :------------------------------------------------------------------- |
| `--url` | URL of the data source to run the command on |
| `--schema` | Path to a Prisma schema file, uses the URL in the `datasource` block |
\* Either `--file` or `--stdin` is required to provide the script input.

One of the following script inputs is required:
:::info

| Options | Description |
| :-------- | :-------------------------------------------------------------------- |
| `--stdin` | Use the terminal standard input as the script to be executed |
| `--file` | Path to a file. The content will be sent as the script to be executed |
**Prisma 7 breaking change**: The `--schema` and `--url` options have been removed. Configure your database connection in `prisma.config.ts` instead.

Other options:

| Options | Required | Description |
| :------- | :------- | :------------------------- |
| `--help` | No | Displays the help message. |
:::

#### Examples

- Take the content of a SQL file located at `./script.sql` and execute it on the database specified by the URL in the `datasource` block of your `schema.prisma` file:
- Execute the content of a SQL script file using the datasource configured in `prisma.config.ts`:

```terminal
prisma db execute --file ./script.sql --schema schema.prisma
prisma db execute --file ./script.sql
```

- Take the SQL script from standard input and execute it on the database specified by the data source URL given in the `DATABASE_URL` environment variable:
- Execute the SQL script from stdin using the configured datasource:

```terminal wrap
echo 'TRUNCATE TABLE dev;' | prisma db execute --stdin --url="$DATABASE_URL"
echo 'TRUNCATE TABLE dev;' | prisma db execute --stdin
```

## Prisma Migrate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,42 @@ The `--skip-generate` flag was removed from `prisma migrate dev` and `prisma db

`migrate dev` and `db push` no longer run `prisma generate` automatically. You must run `prisma generate` explicitly to generate Prisma Client.

### `--schema` and `--url` flags removed from `prisma db execute`

The `--schema` and `--url` flags have been removed from the `prisma db execute` command. Previously, you could use `--schema` to specify the path to your Prisma schema file, or `--url` to specify the database URL directly. Now, the database connection must be configured in `prisma.config.ts`.

#### Before (v6)

```terminal
# Using --schema
prisma db execute --file ./script.sql --schema prisma/schema.prisma

# Using --url
prisma db execute --file ./script.sql --url "$DATABASE_URL"
```

#### After (v7)

Configure your database connection in `prisma.config.ts` instead:

```ts
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config'

export default defineConfig({
schema: 'prisma/schema.prisma',
datasource: {
url: env('DATABASE_URL'),
},
})
```

Then run the command without `--schema` or `--url`:

```terminal
prisma db execute --file ./script.sql
```

### Various environment variables have been removed

We've removed a small selection of Prisma-specific environment variables.
Expand Down
31 changes: 31 additions & 0 deletions content/900-ai/prompts/prisma-7.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,35 @@ Your project will be migrated accordingly using the appropriate adapter.

---

## 11) CLI Flag Changes

### `--schema` and `--url` flags removed from `prisma db execute`

The `--schema` and `--url` flags have been removed from `prisma db execute`. Configure your database connection in `prisma.config.ts` instead.

**Before (v6):**
```bash
# Using --schema
prisma db execute --file ./script.sql --schema prisma/schema.prisma

# Using --url
prisma db execute --file ./script.sql --url "$DATABASE_URL"
```

**After (v7):**
```bash
prisma db execute --file ./script.sql
```

The database URL is now read from `prisma.config.ts`.

### Migration Action

- Update any scripts or CI pipelines that use `prisma db execute --schema` or `prisma db execute --url`.
- Configure your database connection in `prisma.config.ts` instead.

---

## Safety Checks & Edge Cases
- **MongoDB provider** detected → stop and recommend staying on Prisma 6 until v7 MongoDB support returns.
- **Multiple entrypoints** (workers, scripts, tests): apply the same client/adapter/dotenv pattern everywhere.
Expand All @@ -312,5 +341,7 @@ Your project will be migrated accordingly using the appropriate adapter.
- ESM/TS config updates
- Seed script updates
- No automatic removal of Accelerate
- Mapped enum breaking change warning (if applicable)
- CLI flag changes (`--schema` and `--url` removal from `db execute`)

````
Loading