Skip to content

Commit e573327

Browse files
committed
fix detect Nullable type in _getPortableTableColumnDefinition
1 parent cf51f73 commit e573327

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/ClickHouseSchemaManager.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use function is_array;
3131
use function preg_match;
3232
use function preg_replace;
33+
use function str_replace;
3334
use function stripos;
3435
use function strpos;
3536
use function strtolower;
@@ -99,18 +100,25 @@ protected function _getPortableTableColumnDefinition($tableColumn) : Column
99100
{
100101
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
101102

102-
$dbType = $tableColumn['type'];
103-
$length = null;
104-
$fixed = false;
105-
if (stripos(trim($tableColumn['type']), 'fixedstring') === 0) {
103+
$dbType = $columnType = trim($tableColumn['type']);
104+
$length = null;
105+
$fixed = false;
106+
$notnull = true;
107+
108+
if (preg_match('/(Nullable\((\w+)\))/i', $columnType, $matches)) {
109+
$columnType = str_replace($matches[1], $matches[2], $columnType);
110+
$notnull = false;
111+
}
112+
113+
if (stripos($columnType, 'fixedstring') === 0) {
106114
// get length from FixedString definition
107-
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $tableColumn['type']);
115+
$length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $columnType);
108116
$dbType = 'fixedstring';
109117
$fixed = true;
110118
}
111119

112120
$unsigned = false;
113-
if (stripos(trim($tableColumn['type']), 'uint') === 0) {
121+
if (stripos($columnType, 'uint') === 0) {
114122
$unsigned = true;
115123
}
116124

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

127135
$options = [
128136
'length' => $length,
129-
'notnull' => true,
137+
'notnull' => $notnull,
130138
'default' => $default,
131139
'primary' => false,
132140
'fixed' => $fixed,

0 commit comments

Comments
 (0)