drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
21.47k stars 486 forks source link

[BUG]: `drizzle-kit generate` succeeds but generates invalid SQL for `default([])` - Postgres #2432

Open raymondji opened 3 weeks ago

raymondji commented 3 weeks ago

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

0.21.4

Describe the Bug

https://orm.drizzle.team/learn/guides/empty-array-default-value explains the right way to do this, but as someone new to Drizzle it was confusing that drizzle-kit generate accepts default([]) but ends up generating invalid SQL.

Schema before:

  field: varchar("col", { length: 128 }).array(),

Schema after:

  field: varchar("col", { length: 64 }).array().notNull().default([]),

Run drizzle-kit generate - succeeds.

Got SQL in migration file:

ALTER TABLE "table" ALTER COLUMN "col" SET DEFAULT ;--> statement-breakpoint

Run drizzle-kit migrate - postgres invalid syntax error.

Expected behavior

Expected SQL in migration file:

ALTER TABLE "table" ALTER COLUMN "col" SET DEFAULT ARRAY[]::varchar(64)[];--> statement-breakpoint

OR it would be nice if drizzle-kit generate could return an error saying the schema is invalid, instead of succeeding. The type inference for default says it accepts a string[] | SQL<unknown> , so passing [] seems intuitive.

image

Environment & setup

Inside a devcontainer running the mcr.microsoft.com/devcontainers/javascript-node:1-22-bookworm Docker image