Browse Source

add comment to migration

tags/2.0.8
Matvey Vasenin 9 years ago
parent
commit
c0c380e730
  1. 2
      framework/db/ColumnSchemaBuilder.php
  2. 14
      framework/db/Migration.php

2
framework/db/ColumnSchemaBuilder.php

@ -49,7 +49,7 @@ class ColumnSchemaBuilder extends Object
/** /**
* @var mixed comment value of the column. * @var mixed comment value of the column.
*/ */
protected $comment; public $comment;
/** /**

14
framework/db/Migration.php

@ -8,6 +8,7 @@
namespace yii\db; namespace yii\db;
use yii\base\Component; use yii\base\Component;
use yii\db\ColumnSchemaBuilder;
use yii\di\Instance; use yii\di\Instance;
/** /**
@ -258,6 +259,11 @@ class Migration extends Component implements MigrationInterface
echo " > create table $table ..."; echo " > create table $table ...";
$time = microtime(true); $time = microtime(true);
$this->db->createCommand()->createTable($table, $columns, $options)->execute(); $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"; 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 ..."; echo " > add column $column $type to table $table ...";
$time = microtime(true); $time = microtime(true);
$this->db->createCommand()->addColumn($table, $column, $type)->execute(); $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"; 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 ..."; echo " > alter column $column in table $table to $type ...";
$time = microtime(true); $time = microtime(true);
$this->db->createCommand()->alterColumn($table, $column, $type)->execute(); $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"; echo " done (time: " . sprintf('%.3f', microtime(true) - $time) . "s)\n";
} }

Loading…
Cancel
Save