Fix decorateColumnMetaDefault

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2025-12-06 14:37:12 +00:00
parent a9ddaeceb7
commit 9ca09e95cd
2 changed files with 11 additions and 24 deletions

View File

@ -365,30 +365,12 @@ final class ColumnsDefinition
*/
public static function decorateColumnMetaDefault(string|null $default, bool $isNull): array
{
$metaDefault = ['DefaultType' => 'USER_DEFINED', 'DefaultValue' => ''];
switch ($default) {
case null:
$metaDefault['DefaultType'] = $isNull ? 'NULL' : 'NONE';
break;
case 'CURRENT_TIMESTAMP':
case 'current_timestamp()':
$metaDefault['DefaultType'] = 'CURRENT_TIMESTAMP';
break;
case 'UUID':
case 'uuid()':
$metaDefault['DefaultType'] = 'UUID';
break;
default:
$metaDefault['DefaultValue'] = $default;
break;
}
return $metaDefault;
return match ($default) {
null => ['DefaultType' => $isNull ? 'NULL' : 'NONE', 'DefaultValue' => ''],
'CURRENT_TIMESTAMP', 'current_timestamp()' => ['DefaultType' => 'CURRENT_TIMESTAMP', 'DefaultValue' => ''],
'UUID', 'uuid()' => ['DefaultType' => 'UUID', 'DefaultValue' => ''],
default => ['DefaultType' => 'USER_DEFINED', 'DefaultValue' => $default],
};
}
/**

View File

@ -282,6 +282,11 @@ class ColumnsDefinitionTest extends AbstractTestCase
false,
['DefaultType' => 'USER_DEFINED', 'DefaultValue' => '"some\/thing"'],
],
'when Default is an empty string' => [
'',
false,
['DefaultType' => 'USER_DEFINED', 'DefaultValue' => ''],
],
];
}
}