Repository navigation
Description
Problem
PostgreSQL supports extensions to expand what it supports out of the box.
Extensions were implemented in PostgreSQL 9.1 to allow for easier packaging of additions to PostgreSQL. Extensions can package user-visible functions or use hooks in the PostgreSQL to modify how the database does certain processes.
You can activate them with this command: https://www.postgresql.org/docs/14/sql-createextension.html
And PostgreSQL can tell you which ones are installed here: https://www.postgresql.org/docs/14/catalog-pg-extension.html
Here is documentation on how to create one yourself: https://www.postgresql.org/docs/14/extend-extensions.html
Popular PostgreSQL extensions are PostGIS, pg_stat_statements, Timescaledb, ltree and many others. PostgreSQL lists some itself at https://www.postgresql.org/download/products/6-postgresql-extensions/, here is a blog post explaining some of these, and there is a full database listing many available extensions.
Hosted PostgreSQL databases often offer some installed PostgreSQL extensions out of the box, or a list of extensions that are explicitly supported and can be enabled. Some examples:
- AWS RDS PostgreSQL
- Aiven PostgreSQL
- Scalegrid PostgreSQL
- Supabase
- Heroku PostgreSQL
- DigitalOcean PostgreSQL
- Google Cloud SQL
- Azure Database for PostgreSQL
Currently Prisma does not allow you to manage PostgreSQL extensions in a convenient way. This can lead to problems when trying to activate them manually, or use features that require them activated: https://github.com/prisma/prisma/labels/topic%3A%20postgresql-extension There is a manual workaround for Prisma Migrations (see below) but that is hard to discover and does not cover all use and edge cases as it is not deeply integrated into Prisma ORM.
Suggested solution
Somehow reflect the installed or required extensions in Prisma Schema. Optimally this will allow us to both support it in Prisma Introspection, but also Prisma Migrations so they are always installed at the right time and fully support with all our tooling. Features in Prisma schema that require an extension installed, should be able to rely that this is the case.
No suggestion for Prisma schema syntax yet.
Alternatives
- Manage the extension manually via editing of Migration files: https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/enable-native-database-functions
Activity
kokokenada commentedon Jun 15, 2022
Cross referencing: #6471.
This problem has been a major complication as I attempt to change from Hasura migrations to prisma migrate. The work around of adding CREATE EXTENSION pgcrypto; as described by https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/enable-native-database-functions (even as a separate initial migration) simply does not work for me when I run prisma migrate dev. The only workaround I have found so far is to use a shadow database and manually add the extension there.
pimeys commentedon Sep 30, 2022
Internal spec: https://www.notion.so/prismaio/PSL-Proposal-Postgres-Extensions-Declaration-177dbbc76b9340b2870f6c7a4641822a
pimeys commentedon Sep 30, 2022
Epic tasks:
test(db pull): postgresqlExtensions
pimeys commentedon Oct 18, 2022
Implemented as a preview feature in 4.5.0.