Fixes #12735: Fixed yii\console\controllers\MigrateController creating multiple primary keys for field bigPrimaryKey:unsigned

This commit is contained in:
SG5
2016-11-25 16:13:28 +03:00
committed by Alexander Makarov
parent deea3cf798
commit 1141fc81a7
5 changed files with 74 additions and 1 deletions

View File

@ -10,6 +10,7 @@ Yii Framework 2 Change Log
- Bug #9796: Initialization of not existing `yii\grid\ActionColumn` default buttons (arogachev)
- Bug #12681: Changed `data` column type from `text` to `blob` to handle null-byte (`\0`) in serialized RBAC rule properly (silverfire)
- Bug #12714: Fixed `yii\validation\EmailValidator` to prevent false-positives checks when property `checkDns` is set to `true` (silverfire)
- Bug #12735: Fixed `yii\console\controllers\MigrateController` creating multiple primary keys for field `bigPrimaryKey:unsigned` (SG5)
- Bug #12791: Fixed `yii\behaviors\AttributeTypecastBehavior` unable to automatically detect `attributeTypes`, triggering PHP Fatal Error (klimov-paul)
- Bug #12803, #12921: Fixed BC break in `yii.activeForm.js` introduced in #11999. Reverted commit 3ba72da (silverfire)
- Bug #12810: Fixed `yii\rbac\DbManager::getChildRoles()` and `yii\rbac\PhpManager::getChildRoles()` throws an exception when role has no child roles (mysterydragon)

View File

@ -462,7 +462,7 @@ class MigrateController extends BaseMigrateController
protected function addDefaultPrimaryKey(&$fields)
{
foreach ($fields as $field) {
if ($field['decorators'] === 'primaryKey()' || $field['decorators'] === 'bigPrimaryKey()') {
if (false !== strripos($field['decorators'], 'primarykey()')) {
return;
}
}

View File

@ -0,0 +1,32 @@
<?php
return <<<CODE
<?php
use yii\db\Migration;
/**
* Handles the creation of table `{table}`.
*/
class {$class} extends Migration
{
/**
* @inheritdoc
*/
public function up()
{
\$this->createTable('{table}', [
'brand_id' => \$this->bigPrimaryKey()->unsigned(),
]);
}
/**
* @inheritdoc
*/
public function down()
{
\$this->dropTable('{table}');
}
}
CODE;

View File

@ -0,0 +1,32 @@
<?php
return <<<CODE
<?php
use yii\db\Migration;
/**
* Handles the creation of table `{table}`.
*/
class {$class} extends Migration
{
/**
* @inheritdoc
*/
public function up()
{
\$this->createTable('{table}', [
'brand_id' => \$this->primaryKey()->unsigned(),
]);
}
/**
* @inheritdoc
*/
public function down()
{
\$this->dropTable('{table}');
}
}
CODE;

View File

@ -95,6 +95,14 @@ class MigrateControllerTest extends TestCase
'fields' => 'title:primaryKey,body:text:notNull,price:money(11,2)',
]);
$this->assertCommandCreatedFile('create_unsigned_pk', $migrationName, $table, [
'fields' => 'brand_id:primaryKey:unsigned',
]);
$this->assertCommandCreatedFile('create_unsigned_big_pk', $migrationName, $table, [
'fields' => 'brand_id:bigPrimaryKey:unsigned',
]);
$this->assertCommandCreatedFile('create_id_pk', $migrationName, $table, [
'fields' => 'id:primaryKey,
address:string,