drizzle-team / drizzle-team/drizzle-orm

[BUG]: drizzle-kit pull default functions not handled in postgreSQL

Open
#4,956 1 comment 0 reactions 0 assignees View on GitHub
bug bug/fixed-in-beta
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.44.2

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

0.31.5

### Other packages

_No response_

### Describe the Bug

I'm using PostgreSQL.

I have this SQL definition pushed into my DB:
```sql
CREATE TABLE "ticketXRRPP" (
"ticketGroupId" UUID NOT NULL,
"rrppId" UUID NOT NULL,
"code" TEXT NOT NULL DEFAULT upper(substr(md5(random()::text), 1, 6)),
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "ticketXRRPP_pkey" PRIMARY KEY ("ticketGroupId")
);
```

When I run npx drizzle-kit pull, the schema.ts is not typed correctly because upper, substr and md5 are not TS functions:
```ts
export const ticketXrrpp = pgTable("ticketXRRPP", {
ticketGroupId: uuid().primaryKey().notNull(),
rrppId: uuid().notNull(),
code: text().default(upper(substr(md5((random())::text), 1, 6))).notNull(),
createdAt: timestamp({ withTimezone: true, mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
}, (table) => [
uniqueIndex("ticketXRRPP_code_key").using("btree", table.code.asc().nullsLast().op("text_ops")),
foreignKey({
columns: [table.ticketGroupId],
foreignColumns: [ticketGroup.id],
name: "ticketXRRPP_ticketGroupId_fkey"
}).onUpdate("cascade").onDelete("cascade"),
foreignKey({
columns: [table.rrppId],
foreignColumns: [user.id],
name: "ticketXRRPP_rrppId_fkey"
}).onUpdate("cascade").onDelete("restrict"),
]);
```

It should be as following (regarding the `code` column):

```ts
code: text().default(sql`upper(substr(md5((random())::text), 1, 6))`).notNull(),
```

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.