question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[PostgreSQL] - setting a schema clobbers the postgresql `search_path` instead of prepending to `search_path`

See original GitHub issue

Bug description

When

  • postgresql extensions are always installed in a specific namespace (for instance heroku_ext – see Changes to PostgreSQL extension schema management)
  • and that namespace is added to the global postgresql search_path
  • and the prisma datasource url includes a schema=myschema parameter
  • and a migration uses a type from an extension e.g. citext

then the migration fails because the type from the extension is not found.

Migration name: 20220324172504_create_users
Database error code: 42704
Database error:
ERROR: type "citext" does not exist
Position:
  0
  1 -- CreateTable
  2 CREATE TABLE "users" (
  3     "id" UUID NOT NULL DEFAULT gen_random_uuid(),
  4     "email" CITEXT NOT NULL,
DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E42704), message: "type \"citext\" does not exist", detail: None, hint: None, position: Some(Original(101)), where_: None, schema: None, table: None, column: None, datatype:

How to reproduce

I’ve created a github repo with instructions on how to duplicate this:

https://github.com/dojo4/prisma-extension-namespace-issue

Expected behavior

I expect a user table with an email column of type citext to exist.

Prisma information

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: v16.15.1
  • Hosting: Heroku

Prisma Version

prisma                  : 4.1.1
@prisma/client          : 3.15.2
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at ../../../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at ../../../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at ../../../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt 8d8414deb360336e4698a65aa45a1fbaf1ce13d8 (at ../../../../.npm/_npx/2778af9cee32ff87/node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Default Engines Hash    : 8d8414deb360336e4698a65aa45a1fbaf1ce13d8
Studio                  : 0.469.0
Preview Features        : interactiveTransactions

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
copiousfreetimecommented, Aug 12, 2022

One other thought I just had, since in our deployment (heroku) we don’t manage the DATABASE_URL parameter, that is set by heroku automatically, we have to tack on the url parameters via expanding environment variables.

Although we didn’t put in a top level .env, we added a <schema folder>/.env.

It is probably worth noting this use case in the heroku deployment documentation. – I guess I could edit that page on github. Maybe I will 😄 .

0reactions
janpiocommented, Sep 28, 2022

Internal note: Next step is a writeup what this is and what it means.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation: 15: 5.9. Schemas - PostgreSQL
A database contains one or more named schemas, which in turn contain tables. ... The first schema named in the search path is...
Read more >
How do I append a schema to the postgresql database default ...
What I would like to do is append a schema to the default search path. I know I can get the current search...
Read more >
Demystifying Schemas & search_path through Examples
PostgreSQL knows what schema it is currently in based on the schema search path. When PostgreSQL is given an unqualified object name (more ......
Read more >
How does postgres use the schema search path when making ...
Given the following setup: regress=> CREATE SCHEMA A; CREATE SCHEMA regress=> CREATE SCHEMA B; CREATE SCHEMA regress=> SET search_path = B, public; ...
Read more >
PostgreSQL Triggers and Stored Function Basics - Severalnines
Setting the search path for every function is a good practice, as it saves having to prefix database objects with a schema name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found