Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ In PostgreSQL, some native database functions are part of an extension. For exam

To use a PostgreSQL extension, you must first install it on the file system of your database server.

In Prisma versions 4.5.0 and later, you can then activate the extension by declaring it in your Prisma schema with the [`postgresqlExtensions` preview feature](/concepts/components/prisma-schema/postgresql-extensions):
In Prisma versions 5.0.0 and later, you can then activate the extension [by declaring it in your Prisma schema](/concepts/components/prisma-schema/postgresql-extensions):

```prisma file=schema.prisma highlight=3,9;add
```prisma file=schema.prisma highlight=8;add
generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
provider = "prisma-client-js"
}

datasource db {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ title: 'PostgreSQL extensions'
metaTitle: 'How to represent PostgreSQL extensions in your Prisma schema'
metaDescription: 'How to represent PostgreSQL extensions in your Prisma scheme, introspect extensions in your database, and apply changes to extensions with Prisma Migrate'
hidePage: false
preview: true
tocDepth: 3
---

<TopBlock>

This page introduces PostgreSQL extensions and describes how to represent extensions in your Prisma schema, how to introspect existing extensions in your database, and how to apply changes to your extensions to your database with Prisma Migrate.

<Admonition type="warning">
<Admonition type="info">

Support for declaring PostgreSQL extensions in your schema is available in preview for the PostgreSQL connector only in Prisma versions 4.5.0 and later.
PostgreSQL extensions are Generally Available from versions 5.0.0 and later. They were introduced in Preview in version 4.5.0. Make sure you enable the `postgresqlExtensions` Preview feature flag if you are running on a version earlier than 5.0.0.

</Admonition>

Expand All @@ -31,32 +30,16 @@ Note that PostgreSQL's documentation uses the term 'install' to refer to what we

</Admonition>

Prisma's `postgresqlExtensions` preview feature allows you to represent PostgreSQL extensions in your Prisma schema. Note that specific extensions may add functionality that is not currently supported by Prisma. For example, an extension may add a type or index that is not supported by Prisma. This functionality must be implemented on a case-by-case basis and is not provided by this preview feature.

## How to enable the <inlinecode>postgresqlExtensions</inlinecode> preview feature

Representing PostgreSQL extensions in your Prisma schema is currently a preview feature. To enable the `postgresqlExtensions` preview feature, you will need to add the `postgresqlExtensions` feature flag to the `previewFeatures` field of the `generator` block in your Prisma schema file:

```prisma file=schema.prisma highlight=3;add
generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
```
Prisma's PostgreSQL extensions feature allows you to represent PostgreSQL extensions in your Prisma schema. Note that specific extensions may add functionality that is not currently supported by Prisma. For example, an extension may add a type or index that is not supported by Prisma.

## How to represent PostgreSQL extensions in your Prisma schema

To represent PostgreSQL extensions in your Prisma schema, add the `extensions` field to the `datasource` block of your `schema.prisma` file with an array of the extensions that you require. For example, the following schema lists the `hstore`, `pg_trgm` and `postgis` extensions:

```prisma file=schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [hstore(schema: "myHstoreSchema"), pg_trgm, postgis(version: "2.1")]
}
```
Expand All @@ -73,8 +56,8 @@ The `map` argument is useful when the PostgreSQL extension that you want to acti

```prisma file=schema.prisma
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [uuidOssp(map: "uuid-ossp")]
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ The following [Preview](/about/prisma/releases#preview) feature flags are availa
| [`tracing`](/concepts/components/prisma-client/opentelemetry-tracing) | [4.2.0](https://github.com/prisma/prisma/releases/tag/4.2.0) | [Submit feedback](https://github.com/prisma/prisma/issues/14640) |
| [`fieldReference`](/reference/api-reference/prisma-client-reference#compare-columns-in-the-same-table) | [4.3.0](https://github.com/prisma/prisma/releases/tag/4.3.0) | [Submit feedback](https://github.com/prisma/prisma/issues/15068) |
| [`multiSchema`](https://github.com/prisma/prisma/issues/1122#issuecomment-1231773471) | [4.3.0](https://github.com/prisma/prisma/releases/tag/4.3.0) | [Submit feedback](https://github.com/prisma/prisma/issues/15077) |
| [`postgresqlExtensions`](/concepts/components/prisma-schema/postgresql-extensions) | [4.5.0](https://github.com/prisma/prisma/releases/tag/4.5.0) | [Submit feedback](https://github.com/prisma/prisma/issues/15835) |
| [`deno`](/guides/deployment/deployment-guides/deploying-to-deno-deploy) | [4.5.0](https://github.com/prisma/prisma/releases/tag/4.5.0) | [Submit feedback](https://github.com/prisma/prisma/issues/15844) |
| [`extendedWhereUnique`](/reference/api-reference/prisma-client-reference#filter-on-non-unique-fields-with-userwhereuniqueinput) | [4.5.0](https://github.com/prisma/prisma/releases/tag/4.5.0) | [Submit feedback](https://github.com/prisma/prisma/issues/15837) |
| [`views`](/concepts/components/prisma-schema/views) | [4.9.0](https://github.com/prisma/prisma/releases/tag/4.9.0) | [Submit feedback](https://github.com/prisma/prisma/issues/17335) |
Expand Down Expand Up @@ -58,6 +57,7 @@ In the list below, you can find a history of Prisma Client and Prisma schema fea

| Feature | Released into Preview | Released into General Availability |
| ---------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------: |
| [`postgresqlExtensions`](/concepts/components/prisma-schema/postgresql-extensions) | [4.5.0](https://github.com/prisma/prisma/releases/tag/4.5.0) | [5.0.0](https://github.com/prisma/prisma/releases/tag/5.0.0) |
| [`clientExtensions`](/concepts/components/prisma-client/client-extensions) | [4.7.0](https://github.com/prisma/prisma/releases/tag/4.7.0) | [4.16.0](https://github.com/prisma/prisma/releases/tag/4.16.0) |
| [`filteredRelationCount`](/concepts/components/prisma-client/aggregation-grouping-summarizing#filter-the-relation-count) | [4.3.0](https://github.com/prisma/prisma/releases/tag/4.3.0) | [4.16.0](https://github.com/prisma/prisma/releases/tag/4.16.0) |
| [`orderByNulls`](/concepts/components/prisma-client/filtering-and-sorting#sort-with-null-records-first-or-last) | [4.1.0](https://github.com/prisma/prisma/releases/tag/4.1.0) | [4.16.0](https://github.com/prisma/prisma/releases/tag/4.16.0) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ Do not activate extensions outside a migration file if you use Prisma Migrate. T

</Admonition>

In Prisma versions 4.5.0 and later, you can activate the extension by declaring it in your Prisma schema with the [`postgresqlExtensions` preview feature](/concepts/components/prisma-schema/postgresql-extensions):
In Prisma versions 5.0.0 and later, you can activate the extension [`by declaring it in your Prisma schema](/concepts/components/prisma-schema/postgresql-extensions):

```prisma file=schema.prisma highlight=3,9;add
```prisma file=schema.prisma highlight=8;add
generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
provider = "prisma-client-js"
}

datasource db {
Expand All @@ -38,7 +37,7 @@ In earlier versions of Prisma, you must instead add a SQL command to your migrat

## How to install a PostgreSQL extension as part of a migration

This section describes how to add a SQL command to a migration file to activate a PostgreSQL extension. If you manage PostgreSQL extensions in your Prisma schema file with the `postgresqlExtensions` preview feature instead, see [How to migrate PostgreSQL extensions](/concepts/components/prisma-schema/postgresql-extensions#how-to-migrate-postgresql-extensions).
This section describes how to add a SQL command to a migration file to activate a PostgreSQL extension. If you use Prisma version 5.0.0 or later, see [How to migrate PostgreSQL extensions](/concepts/components/prisma-schema/postgresql-extensions#how-to-migrate-postgresql-extensions).

The following example demonstrates how to install the `pgcrypto` extension as part of a migration:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ A `datasource` block accepts the following fields:
| `shadowDatabaseUrl` | No | String (URL) | Connection URL to the shadow database used by Prisma Migrate. Allows you to use a cloud-hosted database as the shadow database. |
| `directUrl` | No | String (URL) | Connection URL for [direct connection to the database](/data-platform/data-proxy/prisma-cli-with-data-proxy#set-a-direct-database-connection-url-in-your-prisma-schema).<br /><br />If you use a connection pooler URL in the `url` argument (for example, if you use the Data Proxy or pgBouncer), Prisma CLI commands [that require a direct connection to the database](/data-platform/data-proxy/prisma-cli-with-data-proxy#prisma-cli-commands-that-require-a-direct-database-connection) use the URL in the `directUrl` argument.<br /><br />The only exception to this is the `prisma studio` command. If you are using a `prisma://` URL in the `url` argument, you may use the [Data Browser](/data-platform) as an alternative to Prisma Studio. |
| `relationMode` | No | String (`foreignKeys`, `prisma`) | Sets whether [referential integrity](/concepts/components/prisma-schema/relations/relation-mode) is enforced by foreign keys in the database or emulated in the Prisma Client.<br /><br />In preview in versions 3.1.1 and later. The field is named `relationMode` in versions 4.5.0 and later, and was previously named `referentialIntegrity`. |
| `extensions` | No | List of strings (PostgreSQL extension names) | Allows you to [represent PostgreSQL extensions in your schema](/concepts/components/prisma-schema/postgresql-extensions#how-to-represent-postgresql-extensions-in-your-prisma-schema). Available in preview for PostgreSQL only in Prisma versions 4.5.0 and later. |
| `extensions` | No | List of strings (PostgreSQL extension names) | Allows you to [represent PostgreSQL extensions in your schema](/concepts/components/prisma-schema/postgresql-extensions#how-to-represent-postgresql-extensions-in-your-prisma-schema). Generally Available in Prisma versions 5.0.0 and later. |

The following providers are available:

Expand Down Expand Up @@ -2742,7 +2742,7 @@ await prisma.user.create({

```prisma
enum Role {
ADMIN @map("admin")
ADMIN @map("admin")
CUSTOMER
}
```
Expand Down Expand Up @@ -2818,8 +2818,8 @@ await prisma.user.create({

```prisma
enum Role {
ADMIN @map("admin")
CUSTOMER @map("customer")
ADMIN @map("admin")
CUSTOMER @map("customer")

@@map("_Role")
}
Expand Down Expand Up @@ -3289,7 +3289,7 @@ model User {

<Admonition type="info">

**Note**: [`gen_random_uuid()` is a PostgreSQL function](https://www.postgresql.org/docs/13/functions-uuid.html). To use it in PostgreSQL versions 12.13 and earlier, you must enable the `pgcrypto` extension.<br /><br />In Prisma versions 4.5.0 and later, you can declare the `pgcrypto` extension in your Prisma schema with the [`postgresqlExtensions` preview feature](/concepts/components/prisma-schema/postgresql-extensions).
**Note**: [`gen_random_uuid()` is a PostgreSQL function](https://www.postgresql.org/docs/13/functions-uuid.html). To use it in PostgreSQL versions 12.13 and earlier, you must enable the `pgcrypto` extension.<br /><br />In Prisma versions 5.0.0 and later, you can declare the `pgcrypto` extension [in your Prisma schema](/concepts/components/prisma-schema/postgresql-extensions).

</Admonition>

Expand Down