yii2
yii2 copied to clipboard
Incorrect default value for BIT columns that allow NULL
What steps will reproduce the problem?
Create a mysql table with a column of type "BIT(1) NULL DEFAULT NULL", and get its schema info from Yii. (here size doesn't matter, so any BIT(N) column is ok).
What is the expected result?
The BIT(N) column's defaultValue shoud be null.
What do you get instead?
The column's defaultValue is 0.
Additional info
Seems like https://github.com/yiisoft/yii2/commit/651e6a3feb0b89405adccdb1db688f6c37106d63 is the original commit, which seems to affect cubrid, mysql, pgsql. I have only tried it with mysql though.
I can make a fix & a pull request but I can only test it with mysql.
| Q | A |
|---|---|
| Yii version | 2.0.35 |
| PHP version | 7.4.7 |
| Operating system | Arch Linux |
So is that about schema introspection only?
It is a good idea to start with a unit test that fails.
Ok, I have some progress, creating a failing test was trickier than I thought, I had to use assertSame() instead of assertEquals() to compare the default value (0 and null). I can't run all tests locally but we should make sure that 85079f8 doesn't break anything.
@trombipeti You can do a pull request so we can view test runs together but the test looks alright along with how it was executed. I think we can proceed with the actual fix. Good job 👍
Seems like this only affects mysql, do you agree?
- cubrid tests aren't currently running in CI.
- You've stated that it may affect pgsql but it's not checked in tests.
I looked quickly in the source and it looked like pgsql wasn't affected, but the newly created unit tests prove otherwise.
I've (hopefully) implemented the fix for all 3 DBMSes.
@samdark @rob006 @bizley I can add the tests for each driver and fix it where it should, this way we would have the bit column working correctly.