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.
- rename class to ColumnSchemaBuilder as this is more appropriate
- changed internal organisation to match how the rest of schema related classes work
- the ColumnSchemaBuilder is now created the same way as QueryBuilder is
- removed static call magic and method annotations, now real methods are called as they are
- the whole code works on objects in a db context now instead of setting database connection in global state
- trait is now used by Migration by default but can be used in other contexts as well
Migration usage is now as follows:
```php
$this->createTable('example_table', [
'id' => $this->primaryKey(),
'name' => $this->string(64)->notNull(),
'type' => $this->integer()->notNull()->defaultValue(10),
'description' => $this->text(),
'rule_name' => $this->string(64),
'data' => $this->text(),
'created_at' => $this->datetime()->notNull(),
'updated_at' => $this->datetime(),
]);
```