diff --git a/src/Schema.php b/src/Schema.php index ffa4dd86..22b7969c 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -24,7 +24,6 @@ use function md5; use function serialize; use function str_contains; -use function stripos; use function strlen; use function substr; use function trim; @@ -442,7 +441,7 @@ protected function createColumn(array|string $column): ColumnSchema $c->phpType($this->getColumnPhpType($c)); if (!$c->isPrimaryKey()) { - if ($column['data_default'] !== null && stripos($column['data_default'], 'timestamp') !== false) { + if ($column['data_default'] === null) { $c->defaultValue(null); } else { $defaultValue = $column['data_default']; @@ -450,17 +449,16 @@ protected function createColumn(array|string $column): ColumnSchema if ($c->getType() === 'timestamp' && $defaultValue === 'CURRENT_TIMESTAMP') { $c->defaultValue(new Expression('CURRENT_TIMESTAMP')); } else { - if ($defaultValue !== null) { - if ( - ($len = strlen($defaultValue)) > 2 && - $defaultValue[0] === "'" && - $defaultValue[$len - 1] === "'" - ) { - $defaultValue = substr((string) $column['data_default'], 1, -1); - } else { - $defaultValue = trim($defaultValue); - } + if ( + ($len = strlen($defaultValue)) > 2 && + $defaultValue[0] === "'" && + $defaultValue[$len - 1] === "'" + ) { + $defaultValue = substr($defaultValue, 1, -1); + } else { + $defaultValue = trim($defaultValue); } + $c->defaultValue($c->phpTypecast($defaultValue)); } } diff --git a/tests/Provider/SchemaProvider.php b/tests/Provider/SchemaProvider.php index 0ca5a3f0..63a539c8 100644 --- a/tests/Provider/SchemaProvider.php +++ b/tests/Provider/SchemaProvider.php @@ -157,7 +157,7 @@ public function columns(): array 'size' => 11, 'precision' => null, 'scale' => 6, - 'defaultValue' => null, + 'defaultValue' => "to_timestamp('2002-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')", ], 'bool_col' => [ 'type' => 'string', @@ -193,7 +193,7 @@ public function columns(): array 'size' => 11, 'precision' => null, 'scale' => 6, - 'defaultValue' => null, + 'defaultValue' => 'CURRENT_TIMESTAMP', ], 'bit_col' => [ 'type' => 'string',