drizzle-team / drizzle-team/drizzle-orm

[BUG]:

Open
#2,427 3 comments 0 reactions 0 assignees View on GitHub
bug bug/fixed-in-beta priority
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

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

0.31.0

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

0.22.1

### Describe the Bug

Creating an index with a where condition

```js
index('locations_open_orders_index')
.on(table.locationId, table.startedAt.desc())
.where(eq(table.open, true))
```

Creates in the migration file:
```sql
CREATE INDEX IF NOT EXISTS "locations_open_orders_index" ON "orders" USING btree (location_id,started_at DESC NULLS LAST) WHERE "orders"."open" = $1;--> statement-breakpoint
```

Which causes the migration to fail with:
```
applying migrations...error: there is no parameter $1
```

The docs say to use
```js
// First example, with `.on()`
index('name')
.on(table.column1.asc(), table.column2.nullsFirst(), ...) or .onOnly(table.column1.desc().nullsLast(), table.column2, ...)
.concurrently()
.where(sql``)
.with({ fillfactor: '70' })
```

With the sql builder instead of the helper functions, and I'm about to use that instead, but there is no reason to suspect the helper functions wouldnt work here.

### Expected behavior

In the migration file it would generate

```sql
CREATE INDEX IF NOT EXISTS "locations_open_orders_index" ON "orders" USING btree (location_id,started_at DESC NULLS LAST) WHERE "orders"."open" = true;
```

### Environment & setup

_No response_

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.