public convertColumnDescription ( Cake\Database\Schema\Table $table, $row ) | ||
$table | Cake\Database\Schema\Table |
public function convertColumnDescription(Table $table, $row)
{
$field = $this->_convertColumn($row['type']);
if ($field['type'] === 'boolean') {
if ($row['default'] === 'true') {
$row['default'] = 1;
}
if ($row['default'] === 'false') {
$row['default'] = 0;
}
}
if (!empty($row['has_serial'])) {
$field['autoIncrement'] = true;
}
$field += ['default' => $this->_defaultValue($row['default']), 'null' => $row['null'] === 'YES' ? true : false, 'collate' => $row['collation_name'], 'comment' => $row['comment']];
$field['length'] = $row['char_length'] ?: $field['length'];
$table->addColumn($row['name'], $field);
}
/** * Test parsing Postgres column types from field description. * * @dataProvider convertColumnProvider * @return void */ public function testConvertColumn($type, $expected) { $field = ['name' => 'field', 'type' => $type, 'null' => 'YES', 'default' => 'Default value', 'comment' => 'Comment section', 'char_length' => null, 'collation_name' => 'ja_JP.utf8']; $expected += ['null' => true, 'default' => 'Default value', 'comment' => 'Comment section', 'collate' => 'ja_JP.utf8']; $driver = $this->getMockBuilder('Cake\\Database\\Driver\\Postgres')->getMock(); $dialect = new PostgresSchema($driver); $table = $this->getMockBuilder('Cake\\Database\\Schema\\Table')->setConstructorArgs(['table'])->getMock(); $table->expects($this->at(0))->method('addColumn')->with('field', $expected); $dialect->convertColumnDescription($table, $field); }