Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -442,25 +441,24 @@ 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'];

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));
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Provider/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -193,7 +193,7 @@ public function columns(): array
'size' => 11,
'precision' => null,
'scale' => 6,
'defaultValue' => null,
'defaultValue' => 'CURRENT_TIMESTAMP',
],
'bit_col' => [
'type' => 'string',
Expand Down