From bde00be202510559ce3bcca25d4a6155cafa02b4 Mon Sep 17 00:00:00 2001 From: andrey-mokhov Date: Mon, 16 May 2016 16:30:20 +0600 Subject: [PATCH] ColumnSchemaBuilder can not work with custom types In our project we use trait with custom types, example: ```php trait MigrationToolTrait { protected function dateTimeWithTZ ($precision = null) { if ('pgsql' === $this->db->driverName) { return $this->getDb()->getSchema()->createColumnSchemaBuilder(sprintf('timestamp(%d) with time zone', $precision)); } return $this->dateTime($precision); } } ``` usage: ```php class m160516_161900_init { use MigrationToolTrait; public function safeUp () { $this->createTable('testing', [ 'id' => $this->primaryKey(), 'startDate' => $this->dateTimeWithTZ()->notNull()->defaultExpression('now()'), ]); } public function safeDown () { $this->dropTable('testing'); } } ``` In version 2.0.8 MigrateController generate notice: PHP Notice 'yii\base\ErrorException' with message 'Undefined index: timestamp(0) with time zone' in vendor/yiisoft/yii2/db/ColumnSchemaBuilder.php:366 We offer our change to fix it. --- framework/db/ColumnSchemaBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/db/ColumnSchemaBuilder.php b/framework/db/ColumnSchemaBuilder.php index 64045529b2f..d425253dfe7 100644 --- a/framework/db/ColumnSchemaBuilder.php +++ b/framework/db/ColumnSchemaBuilder.php @@ -390,7 +390,7 @@ protected function buildAppendString() */ protected function getTypeCategory() { - return $this->categoryMap[$this->type]; + return isset($this->categoryMap[$this->type]) ? $this->categoryMap[$this->type] : null; } /**