volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Bug? TINYINT(1) UNSIGNED cannot be bool as default #573

Closed vuon9 closed 5 years ago

vuon9 commented 5 years ago

What version of SQLBoiler are you using (sqlboiler --version)?

V3.4.0

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

sqlboiler -c sqlboiler.toml --wipe mysql -d

If this happened at runtime what code produced the issue? (if not applicable leave blank)

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

CREATE TABLE tableName (
  is_actived TINYINT(1) UNSIGNED
)

Further information. What did you do, what did you expect?

I expect it generates the model property with bool type.

I think the problem came from these lines because the c.FullDBType of column is different when it is UNSIGNED.

https://github.com/volatiletech/sqlboiler/blob/9c8f3844068160cdfa32077e2fec29fbf4a0b237/drivers/sqlboiler-mysql/driver/mysql.go#L357

https://github.com/volatiletech/sqlboiler/blob/9c8f3844068160cdfa32077e2fec29fbf4a0b237/drivers/sqlboiler-mysql/driver/mysql.go#L409

aarondl commented 5 years ago

What is the full db type when it's unsigned?

vuon9 commented 5 years ago
"full_db_type":"tinyint(1) unsigned"

It is from the CLI log.

aarondl commented 5 years ago

I'm curious if other mysql users expect this same behavior or if this change would be a mistake. Is there any reason why you can't just use tinyint(1)? Is there some documentation you can provide to support this?

I don't use mysql at all, so I'm not "in the know", the tinyint change was proposed a long time ago and came with supporting facts to prove that it was the right thing to do.

Having said that I've already done the change, so if we can show that it's the right thing to do it'll be done quickly.

vuon9 commented 5 years ago

Until I got your answer, I don't really made research about this, just from my idea: UNSIGNED doesn't make the positive number lost 0,1 value then it should works like as the same of non-unsigned. I'm not a SQL guy at all.

After read your answer, I think you're right at your point, based on the mysql document, I think sqlboiler is fine with this one, not a bug.

Thank you.