drizzle-team / drizzle-team/drizzle-orm
[BUG]: Default values for columns with arrays are broken with drizzle-kit push
- 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

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)

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
Assessment
This issue has not been assessed yet.