yii2 icon indicating copy to clipboard operation
yii2 copied to clipboard

Incorrect default value for BIT columns that allow NULL

Open trombipeti opened this issue 5 years ago • 8 comments

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

trombipeti avatar Jun 18 '20 07:06 trombipeti

So is that about schema introspection only?

samdark avatar Jun 18 '20 11:06 samdark

It is a good idea to start with a unit test that fails.

samdark avatar Jun 18 '20 11:06 samdark

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 avatar Jun 22 '20 11:06 trombipeti

@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 👍

samdark avatar Jun 22 '20 17:06 samdark

Seems like this only affects mysql, do you agree?

trombipeti avatar Jun 25 '20 07:06 trombipeti

  1. cubrid tests aren't currently running in CI.
  2. You've stated that it may affect pgsql but it's not checked in tests.

samdark avatar Jun 25 '20 19:06 samdark

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.

trombipeti avatar Jul 02 '20 06:07 trombipeti

@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.

terabytesoftw avatar Oct 27 '23 14:10 terabytesoftw