drizzle-team / drizzle-team/drizzle-orm
[BUG]: drizzle-kit push keeps re-adding an existing UNIQUE NULLS NOT DISTINCT constraint (introspection ignores nullsNotDistinct)
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
**What version of drizzle-orm / drizzle-kit are you using?**
drizzle-orm 0.45.2 / drizzle-kit 0.31.10 (both latest at the time of writing)
**Describe the Bug**
Given a schema with a composite unique constraint using `.nullsNotDistinct()`:
```ts
unique("prices_unique")
.on(t.hallId, t.planId, t.customerTypeId, t.dayOfWeek, t.applyTimeId, t.date)
.nullsNotDistinct()
```
and a PostgreSQL 17.10 database where the constraint **already exists with the exact same definition** (`pg_get_constraintdef` returns `UNIQUE NULLS NOT DISTINCT (hall_id, plan_id, customer_type_id, day_of_week, apply_time_id, date)`), every `drizzle-kit push` run claims the constraint needs to be added:
```
· You're about to add prices_unique unique constraint to the table, which contains 159495378 items.
If this statement fails, you will receive an error from the database.
Do you want to truncate prices table?
```
- In non-interactive environments (CI), this crashes with `Error: Interactive prompts require a TTY terminal` — and the process still **exits with code 0**, so failures go undetected.
- Reproducible recreate-loop: push the schema into an **empty** database ("Changes applied"), then immediately push again — drizzle-kit re-applies the unique constraint every time instead of "No changes detected".
A catalog-level comparison (information_schema / pg_constraint / pg_indexes) between a freshly pushed scratch DB and the target DB shows **zero differences** for this constraint, so the diff appears to come from introspection not reading the NULLS NOT DISTINCT flag (and therefore always treating the schema as different).
**Expected behavior**
`drizzle-kit push` detects the existing `UNIQUE NULLS NOT DISTINCT` constraint as matching the schema and produces no diff. Failed runs should exit non-zero.
**Steps to reproduce**
1. PostgreSQL 17 (docker `postgres:17`)
2. Minimal schema: one table + `unique(...).on(col1, col2).nullsNotDistinct()`
3. `drizzle-kit push` (creates everything)
4. `drizzle-kit push` again → re-adds the unique constraint instead of "No changes detected"
**Environment**: macOS / Bun 1.3.x (`bun x drizzle-kit push`), PostgreSQL 17.10, dialect `postgresql`
**Related**: #3892 (NULLS (NOT) DISTINCT for unique indexes), #3764 / #2888 / #3428 (push re-detecting unique constraints, closed)
Contributor guide
Assessment
This issue has not been assessed yet.