mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-13 22:06:51 +08:00
Fixes #13919: Added option to add comment for created table to migration console command
This commit is contained in:

committed by
Alexander Makarov

parent
f1277d6d21
commit
b953a184e3
@ -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)
|
||||
|
@ -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
Normal file
7
framework/views/_addComments.php
Normal file
@ -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 ?>');
|
@ -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 */
|
||||
|
||||
@ -36,6 +37,13 @@ class <?= $className ?> extends Migration
|
||||
'fields' => $fields,
|
||||
'foreignKeys' => $foreignKeys,
|
||||
])
|
||||
?>
|
||||
<?php if (!empty($tableComment)) {
|
||||
echo $this->render('_addComments', [
|
||||
'table' => $table,
|
||||
'tableComment' => $tableComment,
|
||||
]);
|
||||
}
|
||||
?>
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user