drizzle-team / drizzle-kit-mirror

Docs and issues repository for drizzle-kit
287 stars 16 forks source link

MySQL - Introspection generating default("NULL") in int type #137

Open pedrovrima opened 11 months ago

pedrovrima commented 11 months ago

I am not sure if this is actually a bug or not, but my db had some DEFAULT NULL in it which were introspected as .default("NULL").

This triggers a TS errors if the variable is int(), for example. Since it is not needed in MySQL, I would recommend ignoring these statements when introspecting.

AndriiSherman commented 11 months ago

Fixing, thanks!

AndriiSherman commented 11 months ago

@pedrovrima can't reproduce it. Could you send me a create table statements with which I can reproduce it?

pedrovrima commented 11 months ago

This is part of the .SQL drop of the db that generated the above error. Not sure if it makes a difference, but this was created with Sequelize years ago, dumped and then imported to planet scale. Introspecting from planet scale is generating the default("NULL")

CREATE TABLE `BANDER_REGISTER` (
  `bander_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL COMMENT 'null',
  `code` varchar(3) NOT NULL COMMENT 'null',
  `email` varchar(45) NOT NULL COMMENT 'null',
  `phone` varchar(14) NOT NULL COMMENT 'null',
  `notes` varchar(250) NOT NULL COMMENT 'null',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `original_id` int(11) DEFAULT NULL COMMENT 'null',
  `updated_at` datetime DEFAULT NULL COMMENT 'null',
  `has_changed` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`bander_id`)
);
AndriiSherman commented 11 months ago

Strange, just did the same schema and can't see any default("NULL") after introspection. I'm using drizzle-kit@0.19.11

AndriiSherman commented 11 months ago

I'm also using mysql2@2.3.3, maybe you have v3?

AndriiSherman commented 11 months ago

We will bundle specific driver versions inside drizzle-kit, so it won't make a difference between environments. Didn't have a chance to do it yet

pedrovrima commented 11 months ago

yep - have mysql2@3.4.1 and drizzle-kit@0.18.1.

AndriiSherman commented 11 months ago

So at the latest it should work well, should we close this issue then?

pedrovrima commented 11 months ago

I'll give it a shot later today, but i guess so!

pedrovrima commented 11 months ago

Hey @AndriiSherman , just updated drizzle-kit to 0.19.2 and this issue persists. I am reopening this issue, if you don't mind.

pedrovrima commented 11 months ago

Actually, from PlanetScale it works just fine. the .DEFAULT("NULL") is being generated when I introspect from a MySQL DB hosted in a A2Hosting server