drizzle-team / drizzle-team/drizzle-orm

[BUG]: Wrong operator for index with multiple keys in 0.31.0

Open
#3,736 8 comments 11 reactions 0 assignees View on GitHub
bug bug/fixed-in-beta db/postgres drizzle/kit has-pr priority
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [X] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.38.0

### What version of `drizzle-kit` are you using?

0.30.0

### Other packages

_No response_

### Describe the Bug

When using `drizzle-kit introspect` to pull a schema with indices there are some cases where UUID get the wrong operator:

```typescript
export const keyFigures = mySchema.table(
'keyfigures',
{
id: integer().notNull(),
compUuid: uuid('comp_uuid').notNull(),
year: varchar({ length: 255 }).notNull(),
// ...
},
(table) => [
index('keyfigures__comp_uuid_idx').using(
'btree',
table.compUuid.asc().nullsLast().op('uuid_ops'),
),
index('keyfigures__comp_uuid_year_idx').using(
'btree',
table.compUuid.asc().nullsLast().op('text_ops'),
table.year.asc().nullsLast().op('text_ops'),
),
],
)
```

In the intropected database the indices are as follows:

**keyfigures__comp_uuid_idx:**
![Screenshot 2024-12-10 at 14 50 22](https://github.com/user-attachments/assets/e8124ab3-862d-4d8e-a2f6-f335fc876cbd)

**keyfigures__comp_uuid_year_idx:**
![Screenshot 2024-12-10 at 14 50 51](https://github.com/user-attachments/assets/58102669-890a-4ba5-9a0d-d2f0a82fbcd2)

This throws the following error when I push the schema to my test database:
```
error: operator class "text_ops" does not accept data type uuid
```

**Expectectations:**
I expect the indices in the introspected schema to have the same operator classes as the database they are pulled from

**Details:**
As far as I can tell the issue only arises when there are multiple keys on an index. As you can see above `keyfigures__comp_uuid_idx` resolves to the correct operator class (uuid_ops) while `keyfigures__comp_uuid_year_idx` resolves to text_ops for both keys.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.