drizzle-team / drizzle-team/drizzle-orm

[BUG]: Introspection from PostgreSQL Supabase creates invalid Schema involving double single quotes

Open
#3,820 1 comment 0 reactions 1 assignee Claimed by @L-Mario564 View on GitHub
bug bug/fixed-in-beta db/postgres drizzle/kit has-pr
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?

v0.38.1

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

0.30.0

### Other packages

_No response_

### Describe the Bug

I am using PostgreSQL from Supabase, here one of the schema when instropected:

```ts
export const Guru = pgTable("Guru", {
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: ""Guru_id_seq"", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807 }),
created_at: timestamp({ withTimezone: true, mode: 'string' }).defaultNow().notNull(),
nama_guru: text().notNull(),
nama_panggilan: text(),
});
```

expected

```ts
export const Guru = pgTable("Guru", {
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
id: bigint({ mode: "number" }).primaryKey().generatedByDefaultAsIdentity({ name: "Guru_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807 }),
created_at: timestamp({ withTimezone: true, mode: 'string' }).defaultNow().notNull(),
nama_guru: text().notNull(),
nama_panggilan: text(),
});
```

here the one with the correct schema

```ts
export const NilaiUAS = pgTable("NilaiUAS", {
id: serial().primaryKey().notNull(),
benar: integer().notNull(),
nama_lain_id: integer(),
}, (table) => [
foreignKey({
columns: [table.nama_lain_id],
foreignColumns: [NamaLain.id],
name: "nilai_nama_lain_id_nama_lain_id_fk"
}).onUpdate("cascade").onDelete("cascade"),
]);
```

### My hypothesis

- This occurs when I set the `id` or primary column to the `int8` type, which auto-generates and increments by default in a new Supabase table.

- I think it is specific to the `generatedByDefaultAsIdentity` when doing introspection because other props with `name` has normal quotes

- I see same behavior (double quotes) in #3318 and #1754

### Specific information

`tsconfig.json`

```json
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
```
driver: `postgres` from "postgres"
not monorepo
node version: v20.15.1

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.