Browse Source

Fixed #9574: Implicit run ColumnSchemaBuilder::null() when default value is set to null. (#11813)

ar-bug
Robert Korulczyk 8 years ago committed by Alexander Makarov
parent
commit
099b364b14
  1. 1
      framework/CHANGELOG.md
  2. 6
      framework/db/ColumnSchemaBuilder.php
  3. 2
      tests/framework/db/ColumnSchemaBuilderTest.php
  4. 12
      tests/framework/db/QueryBuilderTest.php

1
framework/CHANGELOG.md

@ -6,6 +6,7 @@ Yii Framework 2 Change Log
----------------------- -----------------------
- Enh #11725: Added indexes on message tables (OndrejVasicek) - Enh #11725: Added indexes on message tables (OndrejVasicek)
- Enh #10422: Added `null` method on `yii\db\ColumnSchemaBuilder` to explicitly set column nullability (nevermnd) - Enh #10422: Added `null` method on `yii\db\ColumnSchemaBuilder` to explicitly set column nullability (nevermnd)
- Enh #9574: Implicit run `ColumnSchemaBuilder::null()` when default value is set to `null`. (rob006)
- Enh #8795: Refactored `yii\web\User::loginByCookie()` in order to make it easier to override (maine-mike, silverfire) - Enh #8795: Refactored `yii\web\User::loginByCookie()` in order to make it easier to override (maine-mike, silverfire)
- Enh #9948: `yii\rbac\PhpManager` now invalidates script file cache performed by 'OPCache' or 'APC' on file saving (klimov-paul) - Enh #9948: `yii\rbac\PhpManager` now invalidates script file cache performed by 'OPCache' or 'APC' on file saving (klimov-paul)
- Enh #11195: Added ability to append custom string to schema builder column definition (df2, samdark) - Enh #11195: Added ability to append custom string to schema builder column definition (df2, samdark)

6
framework/db/ColumnSchemaBuilder.php

@ -180,6 +180,10 @@ class ColumnSchemaBuilder extends Object
*/ */
public function defaultValue($default) public function defaultValue($default)
{ {
if ($default === null) {
$this->null();
}
$this->default = $default; $this->default = $default;
return $this; return $this;
} }
@ -327,7 +331,7 @@ class ColumnSchemaBuilder extends Object
protected function buildDefaultString() protected function buildDefaultString()
{ {
if ($this->default === null) { if ($this->default === null) {
return ''; return $this->isNotNull === false ? ' DEFAULT NULL' : '';
} }
$string = ' DEFAULT '; $string = ' DEFAULT ';

2
tests/framework/db/ColumnSchemaBuilderTest.php

@ -25,7 +25,7 @@ abstract class ColumnSchemaBuilderTest extends TestCase
public function typesProvider() public function typesProvider()
{ {
return [ return [
['integer NULL', Schema::TYPE_INTEGER, null, [ ['integer NULL DEFAULT NULL', Schema::TYPE_INTEGER, null, [
['unsigned'], ['null'], ['unsigned'], ['null'],
]], ]],
['integer(10)', Schema::TYPE_INTEGER, 10, [ ['integer(10)', Schema::TYPE_INTEGER, 10, [

12
tests/framework/db/QueryBuilderTest.php

@ -877,6 +877,18 @@ abstract class QueryBuilderTest extends DatabaseTestCase
], ],
], ],
[ [
Schema::TYPE_TIMESTAMP . ' NULL DEFAULT NULL',
$this->timestamp()->defaultValue(null),
[
'mysql' => 'timestamp NULL DEFAULT NULL',
'postgres' => 'timestamp(0) NULL DEFAULT NULL',
'sqlite' => 'timestamp NULL DEFAULT NULL',
'oci' => 'TIMESTAMP NULL DEFAULT NULL',
'sqlsrv' => 'timestamp NULL DEFAULT NULL',
'cubrid' => 'timestamp NULL DEFAULT NULL',
],
],
[
Schema::TYPE_UPK, Schema::TYPE_UPK,
$this->primaryKey()->unsigned(), $this->primaryKey()->unsigned(),
[ [

Loading…
Cancel
Save