From 483366058f3adbd6c7655a1d73de1c6b24ba4698 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 17 Nov 2024 12:58:40 +0700 Subject: [PATCH] Refactor `ColumnDefinitionBuilder` --- src/Column/ColumnDefinitionBuilder.php | 4 ++-- tests/Provider/QueryBuilderProvider.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Column/ColumnDefinitionBuilder.php b/src/Column/ColumnDefinitionBuilder.php index 0bf498b6..8532fa65 100644 --- a/src/Column/ColumnDefinitionBuilder.php +++ b/src/Column/ColumnDefinitionBuilder.php @@ -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', @@ -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', diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 3f7f26a1..7da99d38 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -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'; @@ -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';