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
24.61k stars 649 forks source link

[BUG]: `introspect` generates invalid schema depending on the default value #3593

Open ooflorent opened 6 hours ago

ooflorent commented 6 hours ago

Report hasn't been filed before.

What version of drizzle-orm are you using?

0.36.3

What version of drizzle-kit are you using?

0.28.1

Other packages

No response

Describe the Bug

Given the following PostgreSQL table definition:

CREATE TABLE "public"."some_table" (
    "id" serial PRIMARY KEY NOT NULL,
    "slug" text NOT NULL DEFAULT ''::text,
    "uuid" varchar NOT NULL DEFAULT md5((random())::text),
    PRIMARY KEY ("id")
);

When running drizzle-kit introspect, the command generates an invalid schema:

    //                    v Missing end quote
    slug: text().default(').notNull(),

    //                     v   Missing sql`…`   v
    uuid: varchar().default(md5((random())::text)).notNull(),