Skip to content

Commit

Permalink
Refactor ColumnDefinitionBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Nov 17, 2024
1 parent 1fe0de5 commit 4833660
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Column/ColumnDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function buildType(ColumnSchemaInterface $column): string
protected function getDbType(ColumnSchemaInterface $column): string
{
/** @psalm-suppress DocblockTypeContradiction */
return match ($column->getType()) {
return $column->getDbType() ?? match ($column->getType()) {
ColumnType::BOOLEAN => 'boolean',
ColumnType::BIT => 'varbit',
ColumnType::TINYINT => $column->isAutoIncrement() ? 'smallserial' : 'smallint',
Expand All @@ -71,7 +71,7 @@ protected function getDbType(ColumnSchemaInterface $column): string
ColumnType::DECIMAL => 'numeric',
ColumnType::MONEY => 'money',
ColumnType::CHAR => 'char',
ColumnType::STRING => 'varchar',
ColumnType::STRING => 'varchar(' . ($column->getSize() ?? 255) . ')',
ColumnType::TEXT => 'text',
ColumnType::BINARY => 'bytea',
ColumnType::UUID => 'uuid',
Expand Down
6 changes: 3 additions & 3 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public static function buildColumnDefinition(): array
$values['bit()'][0] = 'varbit';
$values['bit(1)'][0] = 'varbit(1)';
$values['bit(8)'][0] = 'varbit(8)';
$values['bit(1000)'][0] = 'varbit(1000)';
$values['bit(64)'][0] = 'varbit(64)';
$values['tinyint()'][0] = 'smallint';
$values['tinyint(2)'][0] = 'smallint';
$values['smallint(4)'][0] = 'smallint';
Expand All @@ -582,11 +582,11 @@ public static function buildColumnDefinition(): array
$values['datetime()'][0] = 'timestamp(0)';
$values['datetime(6)'][0] = 'timestamp(6)';
$values['datetime(null)'][0] = 'timestamp';
$values['array()'][0] = 'varchar[]';
$values['array()'][0] = 'varchar(255)[]';
$values['structured()'][0] = 'jsonb';
$values["structured('structured_type')"][0] = 'structured_type';
$values['json()'][0] = 'jsonb';
$values['json(100)'][0] = 'jsonb';
$values["check('value > 5')"][0] = 'integer CHECK ("col_59" > 5)';
$values['unsigned()'][0] = 'integer';
$values['scale(2)'][0] = 'numeric(10,2)';
$values['integer(8)->scale(2)'][0] = 'integer';
Expand Down

0 comments on commit 4833660

Please sign in to comment.