Skip to content

Commit d27594a

Browse files
add mentions of {schema} in postgres adapter docs (#7438)
1 parent c8b5196 commit d27594a

File tree

4 files changed

+65
-13
lines changed

4 files changed

+65
-13
lines changed

content/200-orm/050-overview/500-databases/300-postgresql.mdx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,47 @@ Notice that this code requires the `DATABASE_URL` environment variable to be set
8181

8282
### Notes
8383

84-
#### Specifying a PostgreSQL schema
84+
#### Configuring the schema for Prisma queries (most common case)
8585

86-
You can specify a [PostgreSQL schema](https://www.postgresql.org/docs/current/ddl-schemas.html) by passing in the `schema` option when instantiating `PrismaPg`:
86+
In Prisma 7, you configure the schema that Prisma uses when generating queries by passing a `schema` option when creating the `PrismaPg` instance. This is the recommended approach for most users who previously used the `schema` URL parameter in Prisma 6.
8787

8888
```ts
8989
const adapter = new PrismaPg(
9090
{ connectionString },
91-
{ schema: 'myPostgresSchema' }
91+
{ schema: 'myPostgresSchema' } // Optional: specify the default schema
9292
)
9393
```
9494

95+
:::note
96+
**For Prisma 6 users**: In Prisma 6, you may have used a `?schema=` parameter in your connection URL. In Prisma 7, you must use the `schema` option shown above instead. This change makes the schema configuration more explicit and consistent across database adapters.
97+
:::
98+
99+
#### Configuring the search path for raw SQL queries (less common case)
100+
101+
If you need to set the search path for raw SQL queries (where you refer to tables without schema qualification), use PostgreSQL's native `options` parameter in your connection string. This is only necessary if you're using raw queries that reference tables without their schema name.
102+
103+
```
104+
postgresql://user:pass@host:5432/db?options=-c%20search_path%3Dmyschemaname
105+
```
106+
107+
or with the alternative syntax:
108+
109+
```
110+
postgresql://user:pass@host:5432/db?options=--search_path%3Dmyschemaname
111+
```
112+
113+
Both syntaxes are supported by the underlying `pg` driver. This approach is only needed for raw SQL queries - for Prisma Client queries, use the `schema` option shown above.
114+
95115
## Connection details
96116

97117
### Connection URL
98118

99-
Prisma ORM follows the connection URL format specified by [PostgreSQL's official guidelines](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING), but does not support all arguments and includes additional arguments such as `schema`. Here's an overview of the components needed for a PostgreSQL connection URL:
119+
Prisma ORM follows the connection URL format specified by [PostgreSQL's official guidelines](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING). Note that in Prisma 7, the custom `schema` URL parameter that was available in Prisma 6 is no longer supported. Instead:
120+
121+
1. For configuring the schema used by Prisma's query builder, use the `schema` option when creating the `PrismaPg` instance
122+
2. For setting the search path for raw SQL queries, use PostgreSQL's native `options` parameter in the connection URL
123+
124+
Here's an overview of the components needed for a PostgreSQL connection URL:
100125

101126
![Structure of the PostgreSQL connection URL](./postgresql-connection-string.png)
102127

content/200-orm/050-overview/500-databases/400-mysql.mdx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,14 @@ import 'dotenv/config'
6262
import { PrismaMariaDb } from '@prisma/adapter-mariadb'
6363
import { PrismaClient } from '../generated/prisma/client'
6464

65-
const adapter = new PrismaMariaDb({
66-
host: "localhost",
67-
port: 3306,
68-
connectionLimit: 5
69-
})
65+
const adapter = new PrismaMariaDb(
66+
{
67+
host: "localhost",
68+
port: 3306,
69+
connectionLimit: 5
70+
},
71+
{ schema: 'mySchemaName' } // Optional: specify the default schema/database
72+
)
7073
const prisma = new PrismaClient({ adapter })
7174
```
7275

content/200-orm/050-overview/500-databases/800-sql-server/index.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ const config = {
8181
},
8282
}
8383

84-
const adapter = new PrismaMssql(config)
84+
const adapter = new PrismaMssql(
85+
config,
86+
{ schema: 'mySchemaName' } // Optional: specify the default schema
87+
)
8588
const prisma = new PrismaClient({ adapter })
8689
```
8790

content/200-orm/050-overview/500-databases/890-neon.mdx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,33 @@ You can then use Prisma Client as you normally would with full type-safety. Pris
153153

154154
### Notes
155155

156-
#### Specifying a PostgreSQL schema
156+
#### Configuring the schema for Prisma queries (most common case)
157157

158-
You can specify a [PostgreSQL schema](https://www.postgresql.org/docs/current/ddl-schemas.html) by passing in the `schema` option when instantiating `PrismaNeon`:
158+
In Prisma 7, you configure the schema that Prisma uses when generating queries by passing a `schema` option when creating the `PrismaNeon` instance. This is the recommended approach for most users who previously used the `schema` URL parameter in Prisma 6.
159159

160160
```ts
161161
const adapter = new PrismaNeon(
162162
{ connectionString },
163-
{ schema: 'myPostgresSchema' })
163+
{ schema: 'myPostgresSchema' } // Optional: specify the default schema
164+
)
164165
```
166+
167+
:::note
168+
**For Prisma 6 users**: In Prisma 6, you may have used a `?schema=` parameter in your connection URL. In Prisma 7, you must use the `schema` option shown above instead. This change makes the schema configuration more explicit and consistent across database adapters.
169+
:::
170+
171+
#### Configuring the search path for raw SQL queries (less common case)
172+
173+
If you need to set the search path for raw SQL queries (where you refer to tables without schema qualification), use PostgreSQL's native `options` parameter in your connection string. This is only necessary if you're using raw queries that reference tables without their schema name.
174+
175+
```
176+
postgresql://user:pass@host:5432/db?options=-c%20search_path%3Dmyschemaname
177+
```
178+
179+
or with the alternative syntax:
180+
181+
```
182+
postgresql://user:pass@host:5432/db?options=--search_path%3Dmyschemaname
183+
```
184+
185+
Both syntaxes are supported by the underlying `pg` driver. This approach is only needed for raw SQL queries - for Prisma Client queries, use the `schema` option shown above.

0 commit comments

Comments
 (0)