Skip to content

[BUG]: drizzle-kit pull generates invalid code for MySQL datetime with DEFAULT CURRENT_TIMESTAMP ON UPDATE #5212

@Sangjun-man

Description

@Sangjun-man

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

1.0.0-beta.8-734e789

What version of drizzle-kit are you using?

1.0.0-beta.8-734e789

Other packages

No response

Describe the Bug

When running drizzle-kit pull on a MySQL database with datetime columns that have DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP, the generated schema contains two issues:

Issue 1: new Date("CURRENT_TIMESTAMPZ") generates Invalid Date

DDL:

`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,

Generated:

created_at: datetime().default(new Date("CURRENT_TIMESTAMPZ")).notNull(),

new Date("CURRENT_TIMESTAMPZ") produces Invalid Date in JavaScript.

Issue 2: onUpdateNow() is generated for datetime, but only supported on timestamp

DDL:

 `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

Generated:

 updated_at: datetime().default(new Date("CURRENT_TIMESTAMPZ")).onUpdateNow().notNull(),

This causes a TypeScript error:
Property 'onUpdateNow' does not exist on type 'MySqlDateTimeBuilder'. Did you mean '$onUpdateFn'?

onUpdateNow() is only available on timestamp columns, not datetime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions