Skip to content

Commit

Permalink
ColumnSchemaBuilder can not work with custom types
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrey-mokhov authored and SilverFire committed May 22, 2016
1 parent 77747fc commit bde00be
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion framework/db/ColumnSchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit bde00be

Please sign in to comment.