Skip to content

Commit

Permalink
feat: add support for function as default value
Browse files Browse the repository at this point in the history
  • Loading branch information
vencakrecl committed Jul 7, 2024
1 parent 083647a commit 71709d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use function is_float;
use function is_int;
use function is_string;
use function preg_match;
use function preg_quote;
use function preg_replace;
use function sprintf;
Expand Down Expand Up @@ -1456,6 +1457,10 @@ public function getDefaultValueDeclarationSQL(array $column): string
return ' DEFAULT ' . $default;
}

if ((bool) preg_match('/^[a-zA-Z_]+\(\)$/', $default)) {
return ' DEFAULT ' . $default;
}

return ' DEFAULT ' . $this->quoteStringLiteral($default);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,17 @@ public function testGetDefaultValueDeclarationSQLForDateType(): void
}
}

public function testGetDefaultValueDeclarationSQLForFunctionDefault(): void
{
self::assertEquals(
' DEFAULT gen_random_uuid()',
$this->platform->getDefaultValueDeclarationSQL([
'type' => Type::getType(Types::STRING),
'default' => 'gen_random_uuid()',
]),
);
}

public function testKeywordList(): void
{
$keywordList = $this->platform->getReservedKeywordsList();
Expand Down

0 comments on commit 71709d8

Please sign in to comment.