drizzle-team / drizzle-team/drizzle-orm
[BUG]:Drizzle Kit pull get wrong schema.ts
- 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.45.1
### What version of `drizzle-kit` are you using?
0.31.8
### Other packages
_No response_
### Describe the Bug
i have a postgres table define :
````
CREATE TABLE "articles" (
"id" bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "articles_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
"title" text NOT NULL,
"summary" text,
"cover_asset_id" bigint,
"cover_url" text,
"content_md" text DEFAULT '' NOT NULL,
"content_md_final" text DEFAULT '' NOT NULL,
"status" text DEFAULT 'draft' NOT NULL,
"created_at" timestamptz DEFAULT now() NOT NULL,
"updated_at" timestamptz DEFAULT now() NOT NULL,
CONSTRAINT "articles_status_check" CHECK ("status" IN ('draft', 'ready', 'published', 'archived'))
);
````
when i use drizzle-kit pull to generate schema.ts
i get the schema.ts below, the default(') is a wrong code,which can't compile.
````
export const articles = pgTable("articles", {
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
id: bigint({ mode: "number" }).primaryKey().generatedAlwaysAsIdentity({ name: "articles_id_seq", startWith: 1, increment: 1, minValue: 1, maxValue: 9223372036854775807, cache: 1 }),
title: text().notNull(),
summary: text(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
coverAssetId: bigint("cover_asset_id", { mode: "number" }),
coverUrl: text("cover_url"),
contentMd: text("content_md").default(').notNull(),
contentMdFinal: text("content_md_final").default(').notNull(),
status: text().default('draft').notNull(),
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(),
}, (table) => [
index("idx_articles_status").using("btree", table.status.asc().nullsLast().op("text_ops")),
index("idx_articles_updated_at").using("btree", table.updatedAt.asc().nullsLast().op("timestamptz_ops")),
check("articles_status_check", sql`status = ANY (ARRAY['draft'::text, 'ready'::text, 'published'::text, 'archived'::text])`),
]);
````
Contributor guide
Assessment
This issue has not been assessed yet.