drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.61k stars 649 forks source link

[BUG]:drizzle-kit pull generate wrong schema.ts #3559

Open qazwsxedckll opened 1 week ago

qazwsxedckll commented 1 week ago

Report hasn't been filed before.

What version of drizzle-orm are you using?

0.36.2

What version of drizzle-kit are you using?

0.28.0

Other packages

No response

Describe the Bug

Using Mysql 8.0.39

Table DDL

CREATE TABLE `alert_history` (
`id` bigint AUTO_INCREMENT NOT NULL,
`name` varchar(255) NOT NULL,
`description` varchar(255) NOT NULL DEFAULT '',
`message` varchar(255) NOT NULL DEFAULT '',
`time` timestamp NOT NULL,
`alert_type` varchar(255) NOT NULL,
`priority` int NOT NULL,
`event_name` varchar(255) NOT NULL,
`origin` varchar(255) NOT NULL DEFAULT '',
`origin_property` varchar(255) NOT NULL DEFAULT '',
`origin_property_basetype` varchar(255) NOT NULL DEFAULT '',
CONSTRAINT `alert_history_id` PRIMARY KEY(`id`)
);

generated schema.ts

export const alertHistory = mysqlTable("alert_history", {
    id: bigint({ mode: "number" }).autoincrement().notNull(),
    name: varchar({ length: 255 }).notNull(),
    description: varchar({ length: 255 }).default(').notNull(),
    message: varchar({ length: 255 }).default(').notNull(),
    time: timestamp({ mode: 'string' }).notNull(),
    alertType: varchar("alert_type", { length: 255 }).notNull(),
    priority: int().notNull(),
    eventName: varchar("event_name", { length: 255 }).notNull(),
    origin: varchar({ length: 255 }).default(').notNull(),
    originProperty: varchar("origin_property", { length: 255 }).default(').notNull(),
    originPropertyBasetype: varchar("origin_property_basetype", { length: 255 }).default(').notNull(),
},
(table) => {
    return {
        idxEntityIdTime: index("idx_entity_id_time").on(table.time),
        idxEntityIdName: index("idx_entity_id_name").on(table.name),
        idxTime: index("idx_time").on(table.time),
        alertHistoryId: primaryKey({ columns: [table.id], name: "alert_history_id"}),
    }
});

the default empty string is missing one '