drizzle-team / drizzle-team/drizzle-orm
[BUG]: Introspection from PostgreSQL Supabase creates invalid Schema involving double single quotes
- 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
Assessment
This issue has not been assessed yet.