Skip to content

Commit

Permalink
fix detect Nullable type in _getPortableTableColumnDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
argayash committed Jul 27, 2018
1 parent cf51f73 commit e573327
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/ClickHouseSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use function is_array;
use function preg_match;
use function preg_replace;
use function str_replace;
use function stripos;
use function strpos;
use function strtolower;
Expand Down Expand Up @@ -99,18 +100,25 @@ protected function _getPortableTableColumnDefinition($tableColumn) : Column
{
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);

$dbType = $tableColumn['type'];
$length = null;
$fixed = false;
if (stripos(trim($tableColumn['type']), 'fixedstring') === 0) {
$dbType = $columnType = trim($tableColumn['type']);
$length = null;
$fixed = false;
$notnull = true;

if (preg_match('/(Nullable\((\w+)\))/i', $columnType, $matches)) {
$columnType = str_replace($matches[1], $matches[2], $columnType);
$notnull = false;
}

if (stripos($columnType, 'fixedstring') === 0) {
// get length from FixedString definition
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $tableColumn['type']);
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $columnType);
$dbType = 'fixedstring';
$fixed = true;
}

$unsigned = false;
if (stripos(trim($tableColumn['type']), 'uint') === 0) {
if (stripos($columnType, 'uint') === 0) {
$unsigned = true;
}

Expand All @@ -126,7 +134,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) : Column

$options = [
'length' => $length,
'notnull' => true,
'notnull' => $notnull,
'default' => $default,
'primary' => false,
'fixed' => $fixed,
Expand Down

0 comments on commit e573327

Please sign in to comment.