drizzle-team / drizzle-team/drizzle-orm

[BUG]: functional index generated incorrectly for MySQL

Open
#4,962 3 comments 0 reactions 0 assignees View on GitHub
bug bug/fixed-in-beta
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.44.6

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

0.31.5

### Other packages

_No response_

### Describe the Bug

I'm trying to create a functional index that includes the substring of a column which overflows the max-size of a MySQL index.

``` typescript
export const myTable = mysqlTable(
"my_table",
{
id: varchar("id", { length: 21 }).primaryKey().notNull(),
otherId: varchar("other_id", { length: 21 }),
url: varchar("url" { length: 2048 })
},
(table) => [
uniqueIndex("uniqueUrl").on(
table.otherId,
sql`left(${table.url}, 1024)`,
]
)
```

This tries to run the following SQL:

``` sql
ALTER TABLE `my_table` ADD CONSTRAINT `uniqueUrl ` UNIQUE(`other_id`,`(left(`url``,`1024)))`);
```

I've tried every variation that I can think of and updated to the latest releases of both drizzle-orm and drizzle-kit, but it keeps generating invalid sql.

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.