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.

`Gist` index not supported on prisma schema

See original GitHub issue

Bug description

Hello

I’m introspecting my database and this is the schema that is being generated when I use the prisma cli and run npx prisma db pull.

model appointment {
  account_id String                   @default(dbgenerated("(current_setting('app.account'::text))::uuid")) @db.Uuid
  id         String                   @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  date       Unsupported("tstzrange")
  patient_id String                   @db.Uuid
  is_paid    Boolean                  @default(false)
  is_active  Boolean                  @default(true)
  created_at DateTime                 @default(now()) @db.Timestamptz(6)
  patient    patient                  @relation(fields: [account_id, patient_id], references: [account_id, id], onDelete: NoAction, onUpdate: NoAction, map: "FK_Appointment_patient_id__Patient_id")
  account    account                  @relation(fields: [account_id], references: [id], onDelete: NoAction, onUpdate: NoAction)

  @@id([account_id, id], map: "PK_Appointment_account_id_id")
  @@index([account_id, date], map: "appointment_account_id_date_excl", type: Gist)
}

I get the following error once I try to generate the client by running npx prisma generate.

This is the error.

Error: Schema validation error - Error (query-engine-node-api library)
Error code: P1012
error: Error parsing attribute "@@index": The Gist index field type `Uuid` has no default operator class.
  -->  schema.prisma:54
   | 
53 |   @@id([account_id, id], map: "PK_Appointment_account_id_id")
54 |   @@index([account_id, date], map: "appointment_account_id_date_excl", type: Gist)
   | 

Validation Error Count: 1
[Context: getDmmf]

I thought Gist indexes where supported as stated on https://www.prisma.io/docs/concepts/components/prisma-schema/indexes#index-configuration

How to reproduce

Try to generate the prisma client based from this schema, use the cli npx prisma generate.

model appointment {
  account_id String                   @default(dbgenerated("(current_setting('app.account'::text))::uuid")) @db.Uuid
  id         String                   @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  date       Unsupported("tstzrange")
  patient_id String                   @db.Uuid
  is_paid    Boolean                  @default(false)
  is_active  Boolean                  @default(true)
  created_at DateTime                 @default(now()) @db.Timestamptz(6)
  patient    patient                  @relation(fields: [account_id, patient_id], references: [account_id, id], onDelete: NoAction, onUpdate: NoAction, map: "FK_Appointment_patient_id__Patient_id")
  account    account                  @relation(fields: [account_id], references: [id], onDelete: NoAction, onUpdate: NoAction)

  @@id([account_id, id], map: "PK_Appointment_account_id_id")
  @@index([account_id, date], map: "appointment_account_id_date_excl", type: Gist)
}

Expected behavior

The prisma client is generated with no errors.

Prisma information

model appointment {
  account_id String                   @default(dbgenerated("(current_setting('app.account'::text))::uuid")) @db.Uuid
  id         String                   @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  date       Unsupported("tstzrange")
  patient_id String                   @db.Uuid
  is_paid    Boolean                  @default(false)
  is_active  Boolean                  @default(true)
  created_at DateTime                 @default(now()) @db.Timestamptz(6)
  patient    patient                  @relation(fields: [account_id, patient_id], references: [account_id, id], onDelete: NoAction, onUpdate: NoAction, map: "FK_Appointment_patient_id__Patient_id")
  account    account                  @relation(fields: [account_id], references: [id], onDelete: NoAction, onUpdate: NoAction)

  @@id([account_id, id], map: "PK_Appointment_account_id_id")
  @@index([account_id, date], map: "appointment_account_id_date_excl", type: Gist)
}

Environment & setup

  • macOS
  • Postgres 14
  • Prisma CLI Version : 4.3.1
  • Node 16.15.1

Prisma Version

4.3.1

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
janpiocommented, Sep 7, 2022

Internal: Next step is to try to reproduce locally what @gmwill934 is seeing, and then figure out what is going on with that ops class.

2reactions
gmwill934commented, Sep 6, 2022

Absolutely @janpio

Account

create table account (
	id uuid not null default(gen_random_uuid()) primary key,
	email varchar(64) not null unique,
	password varchar(128) not null,
	first_name varchar(32) not null,
	last_name varchar(32) not null,
	city varchar(32) null,
	state varchar(32) null,
	is_verified boolean default(false) not null,
	created_at timestamp with time zone not null default(now())
);

Patient

create table patient (
	account_id uuid not null default(current_setting('app.account')::uuid) references account(id),
	id uuid not null default(gen_random_uuid()),
	email varchar(64) not null,
	first_name varchar(32) not null,
	last_name varchar(32) not null,
	street varchar(64) null,
	interior varchar(16) null,
	exterior varchar(16) null,
	zip varchar(16) null,
	neighborhood varchar(64) null,
	municipality varchar(64) null,
	city varchar(64) null,
	state varchar(64) null,
	tax_system varchar(16) null,
	country varchar (16) null default('MEX'),
	dob date null,
	rfc varchar(13) null,
	legal_name varchar(128) null,
	facturapi_customer_id varchar(32) null,
	is_active boolean not null default(true),
	created_at timestamp with time zone not null default(now()),
	constraint "PK_Patient_account_id_id" primary key (account_id, id),
	constraint "UQ_Patient_account_id_email" unique (account_id, email)
);

Appointment

create table appointment (
	account_id uuid not null default(current_setting('app.account')::uuid) references account(id),
	id uuid not null default(gen_random_uuid()),
	date tstzrange not null,
	patient_id uuid not null,
	is_paid boolean not null default(false),
	is_active boolean not null default(true),
	created_at timestamp with time zone not null default(now()),
	constraint "PK_Appointment_account_id_id" primary key (account_id, id),
	constraint "FK_Appointment_patient_id__Patient_id" foreign key (account_id, patient_id) references patient (account_id, id),
	exclude using gist (account_id WITH =, date WITH &&),
	constraint "CHECK_Appointment_date_lower_not_null" check (lower(date) is not null),
	constraint "CHECK_Appointment_date_lower_not_infinity" check (lower(date) > '-infinity'),
	constraint "CHECK_Appointment_date_upper_not_null" check (upper(date) is not null),
	constraint "CHECK_Appointment_date_upper_not_infinity" check (upper(date) < 'infinity')
);

Read more comments on GitHub >

github_iconTop Results From Across the Web

Indexes - Prisma
Prisma allows configuration of database indexes, unique constraints and primary key constraints. This is in General Availability in versions 4.0.0 and later ...
Read more >
Support GiST Index type with Postgres · Issue #10634 · prisma ...
Problem. I'm trying to use Prisma with geographic data in PostGIS. · Suggested solution. Allow GiST as an option to the type parameter...
Read more >
How to configure indexes in Prisma - LogRocket Blog
Configuring indexes in Prisma. From Prisma version 3.5.0 and above, indexes can be enabled through the extendedIndexes preview feature. But, ...
Read more >
GIN indexes | YugabyteDB Docs
GIN indexes currently support IndexScan only, not IndexOnlyScan. The difference is that IndexScan uses the results of a scan to the index for...
Read more >
could not open extension control file "/usr/share/postgresql/13 ...
I added the following model to my prisma.schema: ... @@index([geometry], name: "geometry_idx", type: Gist) created_at DateTime ...
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