protected function _convertColumn($column)
{
preg_match('/([a-z\\s]+)(?:\\(([0-9,]+)\\))?/i', $column, $matches);
if (empty($matches)) {
throw new Exception(sprintf('Unable to parse column type from "%s"', $column));
}
$col = strtolower($matches[1]);
$length = null;
if (isset($matches[2])) {
$length = (int) $matches[2];
}
if (in_array($col, ['date', 'time', 'boolean'])) {
return ['type' => $col, 'length' => null];
}
if (strpos($col, 'timestamp') !== false) {
return ['type' => 'timestamp', 'length' => null];
}
if (strpos($col, 'time') !== false) {
return ['type' => 'time', 'length' => null];
}
if ($col === 'serial' || $col === 'integer') {
return ['type' => 'integer', 'length' => 10];
}
if ($col === 'bigserial' || $col === 'bigint') {
return ['type' => 'biginteger', 'length' => 20];
}
if ($col === 'smallint') {
return ['type' => 'integer', 'length' => 5];
}
if ($col === 'inet') {
return ['type' => 'string', 'length' => 39];
}
if ($col === 'uuid') {
return ['type' => 'uuid', 'length' => null];
}
if ($col === 'char' || $col === 'character') {
return ['type' => 'string', 'fixed' => true, 'length' => $length];
}
// money is 'string' as it includes arbitrary text content
// before the number value.
if (strpos($col, 'char') !== false || strpos($col, 'money') !== false) {
return ['type' => 'string', 'length' => $length];
}
if (strpos($col, 'text') !== false) {
return ['type' => 'text', 'length' => null];
}
if ($col === 'bytea') {
return ['type' => 'binary', 'length' => null];
}
if ($col === 'real' || strpos($col, 'double') !== false) {
return ['type' => 'float', 'length' => null];
}
if (strpos($col, 'numeric') !== false || strpos($col, 'decimal') !== false) {
return ['type' => 'decimal', 'length' => null];
}
if (strpos($col, 'json') !== false) {
return ['type' => 'json', 'length' => null];
}
return ['type' => 'text', 'length' => null];
}