Skip to content

[BUG]: Drizzle-kit pulls postgres functions as Typescript methods #4916

@yousefhanbali6

Description

@yousefhanbali6

Report hasn't been filed before.

  • 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.44.5

What version of drizzle-kit are you using?

0.31.4

Other packages

No response

Describe the Bug

When trying to generate a schema.ts using drizzle-kit pull. I encountered two issues:

  1. Had some columns in my tables with default value as jsonb_build_object(). It could not parse it, output:
SyntaxError: Unexpected token 's', "sonb_build_object(" is not valid JSON
    at JSON.parse (<anonymous>)
    at defaultForColumn (/Users/yousefhanbali/Desktop/webapp/WebApp/apps/web/node_modules/drizzle-kit/bin.cjs:20054:55)
    at /Users/yousefhanbali/Desktop/webapp/WebApp/apps/web/node_modules/drizzle-kit/bin.cjs:19618:36
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

This can be fixed by switching default value to {} but it does not make sense to fail

  1. Had some columns with default value as gen_random_uuid(). This column is text, when not specifying a value it falls back to this method.

The schema generated successfully, but the output is not accurate. This is a pg function, but pull treats it as a typescript method. Output:

id: text().default(gen_random_uuid()).notNull(),

It should be

id: text().default(sql`gen_random_uuid()`).notNull(),

Am I missing something here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions