Browse Source

Fixes #13919: Added option to add comment for created table to migration console command

tags/2.0.14
Elvira Sheina 7 years ago committed by Alexander Makarov
parent
commit
b953a184e3
  1. 1
      framework/CHANGELOG.md
  2. 9
      framework/console/controllers/MigrateController.php
  3. 7
      framework/views/_addComments.php
  4. 8
      framework/views/createTableMigration.php

1
framework/CHANGELOG.md

@ -43,6 +43,7 @@ Yii Framework 2 Change Log
- Enh #9137: Added `Access-Control-Allow-Method` header for the OPTIONS request (developeruz)
- Enh #9253: Allow `variations` to be a string for `yii\filters\PageCache` and `yii\widgets\FragmentCache` (schojniak, developeruz)
- Enh #12623: Added `yii\helpers\StringHelper::matchWildcard()` replacing usage of `fnmatch()`, which may be unreliable (klimov-paul)
- Enh #13919: Added option to add comment for created table to migration console command (mixartemev, developeruz)
- Enh #14043: Added `yii\helpers\IpHelper` (silverfire, cebe)
- Enh #14355: Added ability to pass an empty array as a parameter in console command (developeruz)
- Enh #14568: Refactored migration templates to use `safeUp()` and `safeDown()` methods (Kolyunya)

9
framework/console/controllers/MigrateController.php

@ -132,6 +132,11 @@ class MigrateController extends BaseMigrateController
* for creating the object.
*/
public $db = 'db';
/**
* @var string the comment for the table being created.
* @since 2.0.14
*/
public $comment = '';
/**
@ -143,7 +148,7 @@ class MigrateController extends BaseMigrateController
parent::options($actionID),
['migrationTable', 'db'], // global for all actions
$actionID === 'create'
? ['templateFile', 'fields', 'useTablePrefix']
? ['templateFile', 'fields', 'useTablePrefix', 'comment']
: []
);
}
@ -155,6 +160,7 @@ class MigrateController extends BaseMigrateController
public function optionAliases()
{
return array_merge(parent::optionAliases(), [
'c' => 'comment',
'f' => 'fields',
'p' => 'migrationPath',
't' => 'migrationTable',
@ -437,6 +443,7 @@ class MigrateController extends BaseMigrateController
'table' => $this->generateTableName($table),
'fields' => $fields,
'foreignKeys' => $foreignKeys,
'tableComment' => $this->comment,
]));
}

7
framework/views/_addComments.php

@ -0,0 +1,7 @@
<?php
/**
* Creates a call for the method `yii\db\Migration::createTable()`
*/
/* @var $table string the name table */
/* @var $tableComment string the comment table */
?> $this->addCommentOnTable('<?= $table ?>', '<?= $tableComment ?>');

8
framework/views/createTableMigration.php

@ -7,6 +7,7 @@
/* @var $className string the new migration class name without namespace */
/* @var $namespace string the new migration class namespace */
/* @var $table string the name table */
/* @var $tableComment string the comment table */
/* @var $fields array the fields */
/* @var $foreignKeys array the foreign keys */
@ -37,6 +38,13 @@ class <?= $className ?> extends Migration
'foreignKeys' => $foreignKeys,
])
?>
<?php if (!empty($tableComment)) {
echo $this->render('_addComments', [
'table' => $table,
'tableComment' => $tableComment,
]);
}
?>
}
/**

Loading…
Cancel
Save