From c0c380e73014473f9ea5427a19756fb4641b9e4a Mon Sep 17 00:00:00 2001 From: Matvey Vasenin Date: Mon, 17 Aug 2015 11:07:19 +0300 Subject: [PATCH] add comment to migration --- framework/db/ColumnSchemaBuilder.php | 2 +- framework/db/Migration.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/framework/db/ColumnSchemaBuilder.php b/framework/db/ColumnSchemaBuilder.php index f534e40..101d8c3 100644 --- a/framework/db/ColumnSchemaBuilder.php +++ b/framework/db/ColumnSchemaBuilder.php @@ -49,7 +49,7 @@ class ColumnSchemaBuilder extends Object /** * @var mixed comment value of the column. */ - protected $comment; + public $comment; /** diff --git a/framework/db/Migration.php b/framework/db/Migration.php index 7681913..e6abe61 100644 --- a/framework/db/Migration.php +++ b/framework/db/Migration.php @@ -8,6 +8,7 @@ namespace yii\db; use yii\base\Component; +use yii\db\ColumnSchemaBuilder; use yii\di\Instance; /** @@ -258,6 +259,11 @@ class Migration extends Component implements MigrationInterface echo " > create table $table ..."; $time = microtime(true); $this->db->createCommand()->createTable($table, $columns, $options)->execute(); + foreach ($columns as $column => $type) { + if ($type instanceof ColumnSchemaBuilder && $type->comment !== null) { + $this->db->createCommand()->addCommentOnColumn($table, $column, $type->comment)->execute(); + } + } echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n"; } @@ -311,6 +317,9 @@ class Migration extends Component implements MigrationInterface echo " > add column $column $type to table $table ..."; $time = microtime(true); $this->db->createCommand()->addColumn($table, $column, $type)->execute(); + if ($type instanceof ColumnSchemaBuilder && $type->comment !== null) { + $this->db->createCommand()->addCommentOnColumn($table, $column, $type->comment)->execute(); + } echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n"; } @@ -354,6 +363,11 @@ class Migration extends Component implements MigrationInterface echo " > alter column $column in table $table to $type ..."; $time = microtime(true); $this->db->createCommand()->alterColumn($table, $column, $type)->execute(); + + if ($type instanceof ColumnSchemaBuilder && $type->comment !== null) { + $this->db->createCommand()->addCommentOnColumn($table, $column, $type->comment)->execute(); + } + echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n"; }