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.45k stars 641 forks source link

Double quotes on defaults #3318

Open Cadienvan opened 1 year ago

Cadienvan commented 1 year ago

drizzle-kit introspect seems to generate double single quotes on every default value: Screenshot 2023-08-11 alle 14 47 08

AndriiSherman commented 1 year ago

Is it MySQL or Postgres?

Cadienvan commented 1 year ago

MySQL, sorry for not mentioning it

AndriiSherman commented 1 year ago

Can't reproduce this issue. What version of drizzle-kit do you have?

Cadienvan commented 1 year ago

@AndriiSherman we are using drizzle-kit 0.19.12.

Here's how to reproduce the issue.

Create the following table in a MySQL database:

CREATE TABLE `reproducing_issue`.`companies` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `login_provider` varchar(16) NOT NULL DEFAULT 'core',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci;

Now create an introspect.ts as follows:

import type { Config } from "drizzle-kit";

export default {
  schema: "./schema-in/*",
  out: "./schema-out",
  driver: "mysql2",
  dbCredentials: {
    user: "root",
    password: "root",
    host: "127.0.0.1",
    port: 33306,
    database: "reproducing_issue",
  },
} satisfies Config;

And then call this script (I added an "introspect" script in my package.json, but you can achieve the same prefixing with npx):

drizzle-kit introspect:mysql --config=./introspect.ts

This will result in the following schema.ts:

import { mysqlTable, mysqlSchema, AnyMySqlColumn, int, varchar } from "drizzle-orm/mysql-core"
import { sql } from "drizzle-orm"

export const companies = mysqlTable("companies", {
    id: int("id").autoincrement().notNull(),
    loginProvider: varchar("login_provider", { length: 16 }).default(''core'').notNull(),
});

Of course, another thing is related to the import of mysqlSchema, AnyMySqlColumn and sql which are not needed, but the main issue is caused by the ''core'' string.

AndriiSherman commented 1 year ago

I still can't reproduce it. It might also be an issue related to the MySQL version. Could you please provide the exact version of MySQL you are using? I'll try to install the same version and perform some testing

Cadienvan commented 1 year ago

It might be in fact.. We are using a pure Docker image with mariadb:10.6

Rojta commented 1 year ago

Can confirm, experiencing the same issue on 10.3.18-MariaDB-1:10.3.18+maria~bionic.

philippdormann commented 1 year ago

also experiencing this issue on mariadb:10.11.0

Tiaansu commented 7 months ago

also experiencing this issue on mariadb:11.3.0

jdeeburke commented 6 months ago

Also seeing this, mariadb:10.4.11 drizzle-kit@0.20.17

gunnerx64 commented 6 months ago

Also seeing this on mariadb:10.6 in docker drizzle-kit@0.20.17