kitloong / laravel-migrations-generator

Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.
MIT License
2.43k stars 269 forks source link

Update MySQLColumn.php #217

Closed zhaozhenxiang closed 3 months ago

zhaozhenxiang commented 3 months ago

do not break types. tinyint(1) not meaning bool

zhaozhenxiang commented 3 months ago

Hello. I submitted the code to allow users to define conversion rules

kitloong commented 3 months ago

Hi @zhaozhenxiang , thanks for the PR.

I have considered this previously and I have choose to use boolean over tinyint for the following reason:

  1. MySQL doc says BOOL, BOOLEAN are synonyms for TINYINT(1).
  2. Even if we generate TINYINT(1) as $column->tinyInteger(...), the migrated column type would be TINYTINT(4), or TINYINT(3) if unsigned, we can't get TINYINT(1) back.

I believe it is a common pattern in MySQL to treat TINYINT(1) as BOOL. And the migrations generator should generate migrations identical to the existing database, in which, TINYINT(1) should be generated as TINYINT(1).