drizzle-team / drizzle-team/drizzle-orm

[BUG]: Substitution of $1, $2, ... in place of enum values in CHECK constraint when running drizzle-kit generate

Open
#3,713 4 comments 3 reactions 1 assignee Claimed by @L-Mario564 View on GitHub
bug bug/fixed-in-beta 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.37.0

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

0.29.1

### Other packages

_No response_

### Describe the Bug

When using enum values in a sql`` string within a check() constraint, the enum values are not substituted into the string. Instead, the SQL placeholder variables $1, $2, etc. are substituted.

I have the following constraint on a table:

```typescript
checkConstraint: check(
"transaction_type_check",
sql`((${table.transactionType} = ${PaymentTransactionType.ADD_BRAND_TO_BRACKET} AND ${table.brand} IS NOT NULL) OR (${table.transactionType} = ${PaymentTransactionType.ADD_STORE_TO_BRACKET} AND ${table.store} IS NOT NULL))`,
),
```

`PaymentTransactionType` is an enum with string values.

`drizzle-kit generate` produces the following SQL:

```sql
ALTER TABLE "payment_transaction" ADD CONSTRAINT "transaction_type_check" CHECK ((("payment_transaction"."type" = $1 AND "payment_transaction"."brand" IS NOT NULL) OR ("payment_transaction"."type" = $2 AND "payment_transaction"."store" IS NOT NULL)));
```

Instead of `$1` and `$2`, I would expect to see the string values of `PaymentTransactionType.ADD_BRAND_TO_BRACKET` and `PaymentTransactionType.ADD_STORE_TO_BRACKET`.

I use enum types within other sql`` strings elsewhere without issue.

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.