prisma: `prisma db push` Error - `Database error: Error querying the database: db error: ERROR: type "citext" does not exist` but citext extension enabled

Bug description

https://github.com/prisma/prisma/issues/5772 - Similar issue to what is described here.

We are trying to run the prisma commands on Vercel and we keep getting this error.

Our initial migration creates the extensions as suggested above.

CREATE EXTENSION IF NOT EXISTS citext;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

Weirdly, it works absolutely fine locally right now which makes it even harder to debug. The sequence of commands we are running is:

npx prisma migrate reset --force

npx prisma db push --preview-feature

To clarify, the first migration applies fine and then the second command errors. It might be worth noting that we are running against a custom postgres schema so maybe something going on in the shadow db there?

How to reproduce

Steps to reproduce the behavior:

  1. Reset your db with an initial migration to create the required extensions
  2. Run db push to apply the rest of the schema
  3. See error

Expected behavior

db push after the initial migration has been applied should already know about citext has it has been applied before.

Prisma information

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Member {
  id                 String               @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
  createTime         DateTime             @default(dbgenerated("now()"))
  externalId         String?              @unique @db.VarChar(255)
  firstName          String               @db.VarChar(255)
  lastName           String               @db.VarChar(255)
  email              String               @unique @db.Citext
  hashedPassword     String?              @db.VarChar(255)
  workTypes          String[]             @db.VarChar(64)
  useTypes           String[]             @db.VarChar(64)
}

Environment & setup

Currently happening on Vercel

  • Database: PostgreSQL
  • Node.js version: 14
  • Prisma version: 2.21.2

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 9
  • Comments: 15 (5 by maintainers)

Most upvoted comments

have there been any progress on this?

@janpio I think db push activates the extension correctly. The problem is that you can have only a single schema for the extension and that makes it impossible to run tests in parallel. I think it’s more related to this issue: https://github.com/prisma/prisma/issues/14662. Creating the extension in pg_catalog fixes this because it’s shared across all schemas, independently from search_path.

This is a pretty big issue when e.g. wanting to run integration tests. db migrate is pretty slow and seeing as db push should be much faster, being able to use that for a new DB even when using extensions would be very helpful.

I think you’re right. We execute the extensions only to the shadow database, not at all to the actual one.

Plan:

  • Use the describer to describe all extensions: SELECT * FROM pg_extension
  • In the differ, find missing extensions from the actual database. Create them.

I’m still not sure would it be a problem for us when we don’t have the extensions in the PSL.