drizzle-team / drizzle-team/drizzle-orm

[BUG]: Default values for columns with arrays are broken with drizzle-kit push

Open
#4,231 3 comments 8 reactions 0 assignees View on GitHub
bug bug/fixed-in-beta drizzle/kit
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.40.0

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

0.30.5

### Other packages

_No response_

### Describe the Bug

I've ran into 3 different scenarios where running drizzle-kit push migrations and how drizzle infers my database schema with my typescript schema

---
**Scenario 1: `jsonb().array().default([])`**
Errors this to the console
```
[⣻] Pulling schema from database...
undefined:1

SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at C:\Users\samsc\Documents\GitHub\nouns-gg\monorepo\node_modules\drizzle-kit\bin.cjs:19878:66
at Array.map ()
at defaultForColumn (C:\Users\samsc\Documents\GitHub\nouns-gg\monorepo\node_modules\drizzle-kit\bin.cjs:19868:74)
at C:\Users\samsc\Documents\GitHub\nouns-gg\monorepo\node_modules\drizzle-kit\bin.cjs:19465:36
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
```
Where it errors
![Image](https://github.com/user-attachments/assets/4a9cc6af-1cc0-4560-8089-05dd899846a6)

Solution: remove the default

---
**Scenario 2: `text().array().default([])`**
Does not error but cant match `text().array().default([])` with `DEFAULT '{}'::text[]` and will continue to generate ALTER COLUMN statements each time drizzle-kit push is ran (even after the statements are executed)
![Image](https://github.com/user-attachments/assets/25f4ac9c-e41d-4ebd-897a-f5b5e06a2c19)

Solution: remove the default

---
**Bonus**
This is the same outcome to scenario 2, but Drizzle thinks there is a difference between `numeric({ precision: 78 })` and `numeric({ precision: 78, scale: 0 })` even though postgres will treat them the same.

If `numeric({ precision: 78 })` is specified in my drizzle schema and doesn't include the scale property, then drizzle-kit push will always think it needs to run `ALTER COLUMN "column_name" TYPE numeric(78, 0);` on the column since postgres will always type the column as `numeric(78)` instead of `numeric(78, 0)` even after running that statement

Solution: explicitly specify numeric columns as `numeric({ precision: 78, scale: 0 })` instead of leaving scale undefined

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.