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
23.33k stars 570 forks source link

[BUG]: Introspection from MySQL Database creates invalid Schema involving double single quotes. #1754

Open maietta opened 8 months ago

maietta commented 8 months ago

What version of drizzle-orm are you using?

0.29.3

What version of drizzle-kit are you using?

0.20.10-3c347a7

Describe the Bug

When running npm drizzle-kit introspect:mysql, I get a schema that includes double "single quotes" as in the following:

export const content = mysqlTable("content", {
    id: int("id").notNull(),
    virtualPath: varchar("virtual_path", { length: 255 }).notNull(),
    pid: varchar("pid", { length: 750 }).notNull(),
    pageTitle: varchar("page_title", { length: 75 }).default(''Untitled Document'').notNull(),
    navTitle: varchar("nav_title", { length: 25 }).default('NULL'),
    protected: mysqlEnum("protected", ['Y','N']).default(''N'').notNull(),
    metaData: varchar("meta_data", { length: 750 }).default('NULL'),
    content: longtext("content").notNull(),
    navPlacement: longtext("navPlacement").default('NULL'),
    weight: decimal("weight", { precision: 10, scale: 2 }).notNull(),
    dateRecorded: datetime("date_recorded", { mode: 'string'}).notNull(),
    lastModified: timestamp("last_modified", { mode: 'string' }).default('current_timestamp()'),
});

Expected behavior

I expect to see:

export const content = mysqlTable("content", {
    id: int("id").notNull(),
    virtualPath: varchar("virtual_path", { length: 255 }).notNull(),
    pid: varchar("pid", { length: 750 }).notNull(),
    pageTitle: varchar("page_title", { length: 75 }).default('Untitled Document').notNull(),
    navTitle: varchar("nav_title", { length: 25 }).default('NULL'),
    protected: mysqlEnum("protected", ['Y','N']).default('N').notNull(),
    metaData: varchar("meta_data", { length: 750 }).default('NULL'),
    content: longtext("content").notNull(),
    navPlacement: longtext("navPlacement").default('NULL'),
    weight: decimal("weight", { precision: 10, scale: 2 }).notNull(),
    dateRecorded: datetime("date_recorded", { mode: 'string'}).notNull(),
    lastModified: timestamp("last_modified", { mode: 'string' }).default('current_timestamp()'),
});

Environment & setup

Using fresh SvelteKit 2.0 with TypeScript enabled.

ElvinPero commented 8 months ago

@Angelelz I would like to solve this issue. Assign this one to me.

Angelelz commented 8 months ago

You can't solve it because drizzle-kit is not open source yet.

ElvinPero commented 8 months ago

@Angelelz Had been trying to find original code but couldnt now I get why :) Are there any beginner friendly issues I can help with that include coding work?

maietta commented 8 months ago

@ElvinPero the best way would be fork the code, familiarize yourself with it, then scan through the issues.

I appreciate your enthusiasm to help. Thanks.

AndriiSherman commented 7 months ago

Sorry for the late response. I'll take this issue now!

maietta commented 7 months ago

Thank you.

maietta commented 5 months ago

Um, it's back. :(

I tried installing drizzle-kit@beta but that didn't work either.

SvelteKit 2. Using Bun package manager.

maietta commented 3 months ago

It's still present on a fresh setup.

I have to manually clean up the double quotes.

Perhaps this is just a MySQL specific error? Notoby else seems to be complaining and most people are seemingly using PostgreSQL. I will switch the database I'm using and see if this problem goes away. This has been an ongoing problem for more than a half a year for me.

agj commented 1 week ago

Just started trying out Drizzle today and I came across this issue as well. Yes, we have a MySQL database.

Here's a sample of the output I'm getting:

export const aros = mysqlTable("aros", {
    id: int("id").autoincrement().notNull(),
    parentId: int("parent_id").default('NULL'),
    model: varchar("model", { length: 255 }).default(''''),
    foreignKey: int("foreign_key").default('NULL'),
    alias: varchar("alias", { length: 255 }).default(''''),
    lft: int("lft").default('NULL'),
    rght: int("rght").default('NULL'),
},
(table) => {
    return {
        idxArosLftRght: index("idx_aros_lft_rght").on(table.lft, table.rght),
        idxArosAlias: index("idx_aros_alias").on(table.alias),
    }
});

Those .default('NULL')s are also giving me a type error.