From e3e277d3234f8505aa7028cc596ce8bc721f8fa1 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Fri, 13 Sep 2024 08:19:28 +0700 Subject: [PATCH] Separate column type constants (#877) --- CHANGELOG.md | 1 + UPGRADE.md | 2 + src/Constant/ColumnType.php | 100 +++++++++++ src/Constant/PseudoType.php | 37 ++++ src/Schema/Builder/AbstractColumn.php | 55 +++--- src/Schema/Column/AbstractColumnFactory.php | 25 +-- src/Schema/Column/AbstractColumnSchema.php | 4 + src/Schema/Column/BigIntColumnSchema.php | 7 +- src/Schema/Column/BinaryColumnSchema.php | 7 +- src/Schema/Column/BitColumnSchema.php | 7 +- src/Schema/Column/BooleanColumnSchema.php | 7 +- src/Schema/Column/ColumnFactoryInterface.php | 3 + src/Schema/Column/ColumnSchemaInterface.php | 8 +- src/Schema/Column/DoubleColumnSchema.php | 7 +- src/Schema/Column/IntegerColumnSchema.php | 7 +- src/Schema/Column/JsonColumnSchema.php | 7 +- src/Schema/Column/StringColumnSchema.php | 7 +- src/Schema/SchemaInterface.php | 54 ++++++ tests/AbstractQueryBuilderTest.php | 51 +++--- tests/AbstractSchemaTest.php | 10 -- .../Common/CommonColumnSchemaBuilderTest.php | 7 +- tests/Common/CommonCommandTest.php | 25 +-- tests/Common/CommonQueryBuilderTest.php | 10 +- tests/Common/CommonSchemaTest.php | 3 +- tests/Db/Command/CommandTest.php | 21 +-- tests/Db/Schema/ColumnSchemaBuilderTest.php | 6 +- tests/Provider/ColumnFactoryProvider.php | 53 +++--- .../Provider/ColumnSchemaBuilderProvider.php | 23 +-- tests/Provider/ColumnSchemaProvider.php | 18 +- tests/Provider/ColumnTypes.php | 161 +++++++++--------- tests/Provider/CommandProvider.php | 3 +- tests/Provider/QueryBuilderProvider.php | 3 +- 32 files changed, 485 insertions(+), 254 deletions(-) create mode 100644 src/Constant/ColumnType.php create mode 100644 src/Constant/PseudoType.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 803b338a3..0ac0433df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ - Enh #872: Use `#[\SensitiveParameter]` attribute to mark sensitive parameters (@heap-s) - Enh #864: Realize column factory (@Tigrov) - Enh #875: Ignore "Packets out of order..." warnings in `AbstractPdoCommand::internalExecute()` method (@Tigrov) +- Enh #877: Separate column type constants (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 5592abbf3..aac6197ae 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -75,6 +75,8 @@ and the following changes were made: - `Yiisoft\Db\Constant\PhpType` with PHP types constants; - `Yiisoft\Db\Constant\GettypeResult` with `gettype()` function results constants. +- `Yiisoft\Db\Constant\ColumnType` with abstract column types constants. +- `Yiisoft\Db\Constant\PseudoType` with column pseudo-types constants. ### New classes for table columns diff --git a/src/Constant/ColumnType.php b/src/Constant/ColumnType.php new file mode 100644 index 000000000..e7b9578a8 --- /dev/null +++ b/src/Constant/ColumnType.php @@ -0,0 +1,100 @@ +notNull()->defaultValue(0); + * $column = (new Column(ColumnType::INTEGER))->notNull()->defaultValue(0); * ``` * * Provides a fluent interface, which means that the methods can be chained together to create a column schema with @@ -69,29 +70,29 @@ abstract class AbstractColumn implements ColumnInterface /** @psalm-var string[] */ private array $categoryMap = [ - SchemaInterface::TYPE_PK => self::TYPE_CATEGORY_PK, - SchemaInterface::TYPE_UPK => self::TYPE_CATEGORY_PK, - SchemaInterface::TYPE_BIGPK => self::TYPE_CATEGORY_PK, - SchemaInterface::TYPE_UBIGPK => self::TYPE_CATEGORY_PK, - SchemaInterface::TYPE_CHAR => self::TYPE_CATEGORY_STRING, - SchemaInterface::TYPE_STRING => self::TYPE_CATEGORY_STRING, - SchemaInterface::TYPE_TEXT => self::TYPE_CATEGORY_STRING, - SchemaInterface::TYPE_TINYINT => self::TYPE_CATEGORY_NUMERIC, - SchemaInterface::TYPE_SMALLINT => self::TYPE_CATEGORY_NUMERIC, - SchemaInterface::TYPE_INTEGER => self::TYPE_CATEGORY_NUMERIC, - SchemaInterface::TYPE_BIGINT => self::TYPE_CATEGORY_NUMERIC, - SchemaInterface::TYPE_FLOAT => self::TYPE_CATEGORY_NUMERIC, - SchemaInterface::TYPE_DOUBLE => self::TYPE_CATEGORY_NUMERIC, - SchemaInterface::TYPE_DECIMAL => self::TYPE_CATEGORY_NUMERIC, - SchemaInterface::TYPE_DATETIME => self::TYPE_CATEGORY_TIME, - SchemaInterface::TYPE_TIMESTAMP => self::TYPE_CATEGORY_TIME, - SchemaInterface::TYPE_TIME => self::TYPE_CATEGORY_TIME, - SchemaInterface::TYPE_DATE => self::TYPE_CATEGORY_TIME, - SchemaInterface::TYPE_BINARY => self::TYPE_CATEGORY_OTHER, - SchemaInterface::TYPE_BOOLEAN => self::TYPE_CATEGORY_NUMERIC, - SchemaInterface::TYPE_MONEY => self::TYPE_CATEGORY_NUMERIC, - SchemaInterface::TYPE_UUID => self::TYPE_CATEGORY_UUID, - SchemaInterface::TYPE_UUID_PK => self::TYPE_CATEGORY_UUID_PK, + PseudoType::PK => self::TYPE_CATEGORY_PK, + PseudoType::UPK => self::TYPE_CATEGORY_PK, + PseudoType::BIGPK => self::TYPE_CATEGORY_PK, + PseudoType::UBIGPK => self::TYPE_CATEGORY_PK, + ColumnType::CHAR => self::TYPE_CATEGORY_STRING, + ColumnType::STRING => self::TYPE_CATEGORY_STRING, + ColumnType::TEXT => self::TYPE_CATEGORY_STRING, + ColumnType::TINYINT => self::TYPE_CATEGORY_NUMERIC, + ColumnType::SMALLINT => self::TYPE_CATEGORY_NUMERIC, + ColumnType::INTEGER => self::TYPE_CATEGORY_NUMERIC, + ColumnType::BIGINT => self::TYPE_CATEGORY_NUMERIC, + ColumnType::FLOAT => self::TYPE_CATEGORY_NUMERIC, + ColumnType::DOUBLE => self::TYPE_CATEGORY_NUMERIC, + ColumnType::DECIMAL => self::TYPE_CATEGORY_NUMERIC, + ColumnType::DATETIME => self::TYPE_CATEGORY_TIME, + ColumnType::TIMESTAMP => self::TYPE_CATEGORY_TIME, + ColumnType::TIME => self::TYPE_CATEGORY_TIME, + ColumnType::DATE => self::TYPE_CATEGORY_TIME, + ColumnType::BINARY => self::TYPE_CATEGORY_OTHER, + ColumnType::BOOLEAN => self::TYPE_CATEGORY_NUMERIC, + ColumnType::MONEY => self::TYPE_CATEGORY_NUMERIC, + ColumnType::UUID => self::TYPE_CATEGORY_UUID, + PseudoType::UUID_PK => self::TYPE_CATEGORY_UUID_PK, ]; /** @@ -150,8 +151,8 @@ public function comment(string|null $comment): static public function unsigned(): static { $this->type = match ($this->type) { - SchemaInterface::TYPE_PK => SchemaInterface::TYPE_UPK, - SchemaInterface::TYPE_BIGPK => SchemaInterface::TYPE_UBIGPK, + PseudoType::PK => PseudoType::UPK, + PseudoType::BIGPK => PseudoType::UBIGPK, default => $this->type, }; diff --git a/src/Schema/Column/AbstractColumnFactory.php b/src/Schema/Column/AbstractColumnFactory.php index 53bb68745..d4990d050 100644 --- a/src/Schema/Column/AbstractColumnFactory.php +++ b/src/Schema/Column/AbstractColumnFactory.php @@ -4,7 +4,7 @@ namespace Yiisoft\Db\Schema\Column; -use Yiisoft\Db\Schema\SchemaInterface; +use Yiisoft\Db\Constant\ColumnType; use function explode; use function preg_match; @@ -34,6 +34,7 @@ abstract class AbstractColumnFactory implements ColumnFactoryInterface * @return string The abstract database type. * * @psalm-param ColumnInfo $info + * @psalm-return ColumnType::* */ abstract protected function getType(string $dbType, array $info = []): string; @@ -85,21 +86,21 @@ public function fromDefinition(string $definition, array $info = []): ColumnSche public function fromType(string $type, array $info = []): ColumnSchemaInterface { $column = match ($type) { - SchemaInterface::TYPE_BOOLEAN => new BooleanColumnSchema($type), - SchemaInterface::TYPE_BIT => new BitColumnSchema($type), - SchemaInterface::TYPE_TINYINT => new IntegerColumnSchema($type), - SchemaInterface::TYPE_SMALLINT => new IntegerColumnSchema($type), - SchemaInterface::TYPE_INTEGER => PHP_INT_SIZE !== 8 && !empty($info['unsigned']) + ColumnType::BOOLEAN => new BooleanColumnSchema($type), + ColumnType::BIT => new BitColumnSchema($type), + ColumnType::TINYINT => new IntegerColumnSchema($type), + ColumnType::SMALLINT => new IntegerColumnSchema($type), + ColumnType::INTEGER => PHP_INT_SIZE !== 8 && !empty($info['unsigned']) ? new BigIntColumnSchema($type) : new IntegerColumnSchema($type), - SchemaInterface::TYPE_BIGINT => PHP_INT_SIZE !== 8 || !empty($info['unsigned']) + ColumnType::BIGINT => PHP_INT_SIZE !== 8 || !empty($info['unsigned']) ? new BigIntColumnSchema($type) : new IntegerColumnSchema($type), - SchemaInterface::TYPE_DECIMAL => new DoubleColumnSchema($type), - SchemaInterface::TYPE_FLOAT => new DoubleColumnSchema($type), - SchemaInterface::TYPE_DOUBLE => new DoubleColumnSchema($type), - SchemaInterface::TYPE_BINARY => new BinaryColumnSchema($type), - SchemaInterface::TYPE_JSON => new JsonColumnSchema($type), + ColumnType::DECIMAL => new DoubleColumnSchema($type), + ColumnType::FLOAT => new DoubleColumnSchema($type), + ColumnType::DOUBLE => new DoubleColumnSchema($type), + ColumnType::BINARY => new BinaryColumnSchema($type), + ColumnType::JSON => new JsonColumnSchema($type), default => new StringColumnSchema($type), }; diff --git a/src/Schema/Column/AbstractColumnSchema.php b/src/Schema/Column/AbstractColumnSchema.php index 2ae050bb9..8281163a5 100644 --- a/src/Schema/Column/AbstractColumnSchema.php +++ b/src/Schema/Column/AbstractColumnSchema.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Schema\Column; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Constant\PhpType; use function is_array; @@ -50,6 +51,9 @@ abstract class AbstractColumnSchema implements ColumnSchemaInterface private int|null $size = null; private bool $unsigned = false; + /** + * @psalm-param ColumnType::* $type + */ public function __construct( private string $type, ) { diff --git a/src/Schema/Column/BigIntColumnSchema.php b/src/Schema/Column/BigIntColumnSchema.php index 4a267c48a..ebb9a9c41 100644 --- a/src/Schema/Column/BigIntColumnSchema.php +++ b/src/Schema/Column/BigIntColumnSchema.php @@ -4,10 +4,10 @@ namespace Yiisoft\Db\Schema\Column; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Constant\GettypeResult; use Yiisoft\Db\Constant\PhpType; -use Yiisoft\Db\Schema\SchemaInterface; use function gettype; @@ -16,8 +16,11 @@ class BigIntColumnSchema extends AbstractColumnSchema { + /** + * @psalm-param ColumnType::* $type + */ public function __construct( - string $type = SchemaInterface::TYPE_BIGINT, + string $type = ColumnType::BIGINT, ) { parent::__construct($type); } diff --git a/src/Schema/Column/BinaryColumnSchema.php b/src/Schema/Column/BinaryColumnSchema.php index 361bb8e02..2109d2e84 100644 --- a/src/Schema/Column/BinaryColumnSchema.php +++ b/src/Schema/Column/BinaryColumnSchema.php @@ -6,16 +6,19 @@ use PDO; use Yiisoft\Db\Command\Param; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Constant\GettypeResult; -use Yiisoft\Db\Schema\SchemaInterface; use function gettype; class BinaryColumnSchema extends AbstractColumnSchema { + /** + * @psalm-param ColumnType::* $type + */ public function __construct( - string $type = SchemaInterface::TYPE_BINARY, + string $type = ColumnType::BINARY, ) { parent::__construct($type); } diff --git a/src/Schema/Column/BitColumnSchema.php b/src/Schema/Column/BitColumnSchema.php index e0958adcb..973a64635 100644 --- a/src/Schema/Column/BitColumnSchema.php +++ b/src/Schema/Column/BitColumnSchema.php @@ -4,14 +4,17 @@ namespace Yiisoft\Db\Schema\Column; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Constant\PhpType; use Yiisoft\Db\Expression\ExpressionInterface; -use Yiisoft\Db\Schema\SchemaInterface; class BitColumnSchema extends AbstractColumnSchema { + /** + * @psalm-param ColumnType::* $type + */ public function __construct( - string $type = SchemaInterface::TYPE_BIT, + string $type = ColumnType::BIT, ) { parent::__construct($type); } diff --git a/src/Schema/Column/BooleanColumnSchema.php b/src/Schema/Column/BooleanColumnSchema.php index deb44f799..6ea80f9b5 100644 --- a/src/Schema/Column/BooleanColumnSchema.php +++ b/src/Schema/Column/BooleanColumnSchema.php @@ -4,14 +4,17 @@ namespace Yiisoft\Db\Schema\Column; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Constant\PhpType; -use Yiisoft\Db\Schema\SchemaInterface; class BooleanColumnSchema extends AbstractColumnSchema { + /** + * @psalm-param ColumnType::* $type + */ public function __construct( - string $type = SchemaInterface::TYPE_BOOLEAN, + string $type = ColumnType::BOOLEAN, ) { parent::__construct($type); } diff --git a/src/Schema/Column/ColumnFactoryInterface.php b/src/Schema/Column/ColumnFactoryInterface.php index 6f4656d5b..d1e35ec5e 100644 --- a/src/Schema/Column/ColumnFactoryInterface.php +++ b/src/Schema/Column/ColumnFactoryInterface.php @@ -4,6 +4,8 @@ namespace Yiisoft\Db\Schema\Column; +use Yiisoft\Db\Constant\ColumnType; + /** * The interface must be implemented by a column factory class. It should create a column schema for a database column * type and initialize column information. @@ -38,6 +40,7 @@ public function fromDefinition(string $definition, array $info = []): ColumnSche * @param string $type The abstract database type. * @param array $info The column information. * + * @psalm-param ColumnType::* $type * @psalm-param ColumnInfo $info The set of parameters may be different for a specific DBMS. */ public function fromType(string $type, array $info = []): ColumnSchemaInterface; diff --git a/src/Schema/Column/ColumnSchemaInterface.php b/src/Schema/Column/ColumnSchemaInterface.php index 5af2cee77..99a743928 100644 --- a/src/Schema/Column/ColumnSchemaInterface.php +++ b/src/Schema/Column/ColumnSchemaInterface.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Schema\Column; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Constant\PhpType; /** @@ -26,7 +27,7 @@ * schema?: string|null, * size?: int|string|null, * table?: string|null, - * type?: string, + * type?: ColumnType::*, * unsigned?: bool|string, * ... * } @@ -206,8 +207,6 @@ public function getPrecision(): int|null; * * @return string The PHP type of the column. * @psalm-return PhpType::* - * - * @see PhpType */ public function getPhpType(): string; @@ -227,6 +226,7 @@ public function getSize(): int|null; /** * @return string The type of the column. + * @psalm-return ColumnType::* * * @see type() */ @@ -349,6 +349,8 @@ public function size(int|null $size): static; * $columns = [ * 'description' => $this->text()->type('text'), * ]; + * + * @psalm-param ColumnType::* $type */ public function type(string $type): static; diff --git a/src/Schema/Column/DoubleColumnSchema.php b/src/Schema/Column/DoubleColumnSchema.php index 515bb611f..a84031329 100644 --- a/src/Schema/Column/DoubleColumnSchema.php +++ b/src/Schema/Column/DoubleColumnSchema.php @@ -4,16 +4,19 @@ namespace Yiisoft\Db\Schema\Column; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Constant\PhpType; -use Yiisoft\Db\Schema\SchemaInterface; use function is_float; class DoubleColumnSchema extends AbstractColumnSchema { + /** + * @psalm-param ColumnType::* $type + */ public function __construct( - string $type = SchemaInterface::TYPE_DOUBLE, + string $type = ColumnType::DOUBLE, ) { parent::__construct($type); } diff --git a/src/Schema/Column/IntegerColumnSchema.php b/src/Schema/Column/IntegerColumnSchema.php index 47c6930f0..27cd92b58 100644 --- a/src/Schema/Column/IntegerColumnSchema.php +++ b/src/Schema/Column/IntegerColumnSchema.php @@ -4,16 +4,19 @@ namespace Yiisoft\Db\Schema\Column; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Constant\PhpType; -use Yiisoft\Db\Schema\SchemaInterface; use function is_int; class IntegerColumnSchema extends AbstractColumnSchema { + /** + * @psalm-param ColumnType::* $type + */ public function __construct( - string $type = SchemaInterface::TYPE_INTEGER, + string $type = ColumnType::INTEGER, ) { parent::__construct($type); } diff --git a/src/Schema/Column/JsonColumnSchema.php b/src/Schema/Column/JsonColumnSchema.php index 50d1e7239..cf4015351 100644 --- a/src/Schema/Column/JsonColumnSchema.php +++ b/src/Schema/Column/JsonColumnSchema.php @@ -4,17 +4,20 @@ namespace Yiisoft\Db\Schema\Column; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Expression\JsonExpression; -use Yiisoft\Db\Schema\SchemaInterface; use function is_string; use function json_decode; class JsonColumnSchema extends AbstractColumnSchema { + /** + * @psalm-param ColumnType::* $type + */ public function __construct( - string $type = SchemaInterface::TYPE_JSON, + string $type = ColumnType::JSON, ) { parent::__construct($type); } diff --git a/src/Schema/Column/StringColumnSchema.php b/src/Schema/Column/StringColumnSchema.php index e11290149..c2b6c6510 100644 --- a/src/Schema/Column/StringColumnSchema.php +++ b/src/Schema/Column/StringColumnSchema.php @@ -4,17 +4,20 @@ namespace Yiisoft\Db\Schema\Column; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Constant\GettypeResult; use Yiisoft\Db\Constant\PhpType; -use Yiisoft\Db\Schema\SchemaInterface; use function gettype; class StringColumnSchema extends AbstractColumnSchema { + /** + * @psalm-param ColumnType::* $type + */ public function __construct( - string $type = SchemaInterface::TYPE_STRING, + string $type = ColumnType::STRING, ) { parent::__construct($type); } diff --git a/src/Schema/SchemaInterface.php b/src/Schema/SchemaInterface.php index 225e145b2..2cb0e11c5 100644 --- a/src/Schema/SchemaInterface.php +++ b/src/Schema/SchemaInterface.php @@ -6,6 +6,8 @@ use Throwable; use Yiisoft\Db\Command\DataType; +use Yiisoft\Db\Constant\ColumnType; +use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Constraint\ConstraintSchemaInterface; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; @@ -121,106 +123,158 @@ interface SchemaInterface extends ConstraintSchemaInterface public const INDEX_BITMAP = 'BITMAP'; /** * Define the abstract column type as a primary key. + * + * @deprecated Use {@see PseudoType::PK} instead. Will be removed in 2.0. */ public const TYPE_PK = 'pk'; /** * Define the abstract column type as an `unsigned` primary key. + * + * @deprecated Use {@see PseudoType::UPK} instead. Will be removed in 2.0. */ public const TYPE_UPK = 'upk'; /** * Define the abstract column type as big primary key. + * + * @deprecated Use {@see PseudoType::BIGPK} instead. Will be removed in 2.0. */ public const TYPE_BIGPK = 'bigpk'; /** * Define the abstract column type as `unsigned` big primary key. + * + * @deprecated Use {@see PseudoType::UBIGPK} instead. Will be removed in 2.0. */ public const TYPE_UBIGPK = 'ubigpk'; /** * Define the abstract column type as an `uuid` primary key. + * + * @deprecated Use {@see PseudoType::UUID_PK} instead. Will be removed in 2.0. */ public const TYPE_UUID_PK = 'uuid_pk'; /** * Define the abstract column type as an`uuid` primary key with a sequence. + * + * @deprecated Use {@see PseudoType::UUID_PK_SEQ} instead. Will be removed in 2.0. */ public const TYPE_UUID_PK_SEQ = 'uuid_pk_seq'; /** * Define the abstract column type as `uuid`. + * + * @deprecated Use {@see ColumnType::UUID} instead. Will be removed in 2.0. */ public const TYPE_UUID = 'uuid'; /** * Define the abstract column type as `char`. + * + * @deprecated Use {@see ColumnType::CHAR} instead. Will be removed in 2.0. */ public const TYPE_CHAR = 'char'; /** * Define the abstract column type as `string`. + * + * @deprecated Use {@see ColumnType::STRING} instead. Will be removed in 2.0. */ public const TYPE_STRING = 'string'; /** * Define the abstract column type as `text`. + * + * @deprecated Use {@see ColumnType::TEXT} instead. Will be removed in 2.0. */ public const TYPE_TEXT = 'text'; /** * Define the abstract column type as `tinyint`. + * + * @deprecated Use {@see ColumnType::TINYINT} instead. Will be removed in 2.0. */ public const TYPE_TINYINT = 'tinyint'; /** * Define the abstract column type as `smallint`. + * + * @deprecated Use {@see ColumnType::SMALLINT} instead. Will be removed in 2.0. */ public const TYPE_SMALLINT = 'smallint'; /** * Define the abstract column type as `integer`. + * + * @deprecated Use {@see ColumnType::INTEGER} instead. Will be removed in 2.0. */ public const TYPE_INTEGER = 'integer'; /** * Define the abstract column type as `bigint`. + * + * @deprecated Use {@see ColumnType::BIGINT} instead. Will be removed in 2.0. */ public const TYPE_BIGINT = 'bigint'; /** * Define the abstract column type as `float`. + * + * @deprecated Use {@see ColumnType::FLOAT} instead. Will be removed in 2.0. */ public const TYPE_FLOAT = 'float'; /** * Define the abstract column type as `double`. + * + * @deprecated Use {@see ColumnType::DOUBLE} instead. Will be removed in 2.0. */ public const TYPE_DOUBLE = 'double'; /** * Define the abstract column type as `decimal`. + * + * @deprecated Use {@see ColumnType::DECIMAL} instead. Will be removed in 2.0. */ public const TYPE_DECIMAL = 'decimal'; /** * Define the abstract column type as `datetime`. + * + * @deprecated Use {@see ColumnType::DATETIME} instead. Will be removed in 2.0. */ public const TYPE_DATETIME = 'datetime'; /** * Define the abstract column type as `timestamp`. + * + * @deprecated Use {@see ColumnType::TIMESTAMP} instead. Will be removed in 2.0. */ public const TYPE_TIMESTAMP = 'timestamp'; /** * Define the abstract column type as `time`. + * + * @deprecated Use {@see ColumnType::TIME} instead. Will be removed in 2.0. */ public const TYPE_TIME = 'time'; /** * Define the abstract column type as `date`. + * + * @deprecated Use {@see ColumnType::DATE} instead. Will be removed in 2.0. */ public const TYPE_DATE = 'date'; /** * Define the abstract column type as `binary`. + * + * @deprecated Use {@see ColumnType::BINARY} instead. Will be removed in 2.0. */ public const TYPE_BINARY = 'binary'; /** * Define the abstract column type as `boolean`. + * + * @deprecated Use {@see ColumnType::BOOLEAN} instead. Will be removed in 2.0. */ public const TYPE_BOOLEAN = 'boolean'; /** * Define the abstract column type as `bit`. + * + * @deprecated Use {@see ColumnType::BIT} instead. Will be removed in 2.0. */ public const TYPE_BIT = 'bit'; /** * Define the abstract column type as `money`. + * + * @deprecated Use {@see ColumnType::MONEY} instead. Will be removed in 2.0. */ public const TYPE_MONEY = 'money'; /** * Define the abstract column type as `json`. + * + * @deprecated Use {@see ColumnType::JSON} instead. Will be removed in 2.0. */ public const TYPE_JSON = 'json'; diff --git a/tests/AbstractQueryBuilderTest.php b/tests/AbstractQueryBuilderTest.php index 647c3a444..c1fc66be9 100644 --- a/tests/AbstractQueryBuilderTest.php +++ b/tests/AbstractQueryBuilderTest.php @@ -11,6 +11,8 @@ use Throwable; use Yiisoft\Db\Command\DataType; use Yiisoft\Db\Command\Param; +use Yiisoft\Db\Constant\ColumnType; +use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; @@ -25,7 +27,6 @@ use Yiisoft\Db\QueryBuilder\Condition\SimpleCondition; use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Schema\QuoterInterface; -use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Tests\Support\Assert; use Yiisoft\Db\Tests\Support\DbHelper; use Yiisoft\Db\Tests\Support\TestTrait; @@ -193,13 +194,13 @@ public function testAlterColumn(): void $db = $this->getConnection(); $qb = $db->getQueryBuilder(); - $sql = $qb->alterColumn('customer', 'email', SchemaInterface::TYPE_STRING); + $sql = $qb->alterColumn('customer', 'email', ColumnType::STRING); $this->assertSame( DbHelper::replaceQuotes( <<getColumnType(SchemaInterface::TYPE_STRING), + SQL . ' ' . $qb->getColumnType(ColumnType::STRING), $db->getDriverName(), ), $sql, @@ -1847,28 +1848,28 @@ public function testGetColumnType(): void $qb = $db->getQueryBuilder(); - $this->assertSame('pk', $qb->getColumnType(SchemaInterface::TYPE_PK)); - $this->assertSame('upk', $qb->getColumnType(SchemaInterface::TYPE_UPK)); - $this->assertSame('bigpk', $qb->getColumnType(SchemaInterface::TYPE_BIGPK)); - $this->assertSame('ubigpk', $qb->getColumnType(SchemaInterface::TYPE_UBIGPK)); - $this->assertSame('char', $qb->getColumnType(SchemaInterface::TYPE_CHAR)); - $this->assertSame('string', $qb->getColumnType(SchemaInterface::TYPE_STRING)); - $this->assertSame('text', $qb->getColumnType(SchemaInterface::TYPE_TEXT)); - $this->assertSame('tinyint', $qb->getColumnType(SchemaInterface::TYPE_TINYINT)); - $this->assertSame('smallint', $qb->getColumnType(SchemaInterface::TYPE_SMALLINT)); - $this->assertSame('integer', $qb->getColumnType(SchemaInterface::TYPE_INTEGER)); - $this->assertSame('bigint', $qb->getColumnType(SchemaInterface::TYPE_BIGINT)); - $this->assertSame('float', $qb->getColumnType(SchemaInterface::TYPE_FLOAT)); - $this->assertSame('double', $qb->getColumnType(SchemaInterface::TYPE_DOUBLE)); - $this->assertSame('decimal', $qb->getColumnType(SchemaInterface::TYPE_DECIMAL)); - $this->assertSame('datetime', $qb->getColumnType(SchemaInterface::TYPE_DATETIME)); - $this->assertSame('timestamp', $qb->getColumnType(SchemaInterface::TYPE_TIMESTAMP)); - $this->assertSame('time', $qb->getColumnType(SchemaInterface::TYPE_TIME)); - $this->assertSame('date', $qb->getColumnType(SchemaInterface::TYPE_DATE)); - $this->assertSame('binary', $qb->getColumnType(SchemaInterface::TYPE_BINARY)); - $this->assertSame('boolean', $qb->getColumnType(SchemaInterface::TYPE_BOOLEAN)); - $this->assertSame('money', $qb->getColumnType(SchemaInterface::TYPE_MONEY)); - $this->assertSame('json', $qb->getColumnType(SchemaInterface::TYPE_JSON)); + $this->assertSame('pk', $qb->getColumnType(PseudoType::PK)); + $this->assertSame('upk', $qb->getColumnType(PseudoType::UPK)); + $this->assertSame('bigpk', $qb->getColumnType(PseudoType::BIGPK)); + $this->assertSame('ubigpk', $qb->getColumnType(PseudoType::UBIGPK)); + $this->assertSame('char', $qb->getColumnType(ColumnType::CHAR)); + $this->assertSame('string', $qb->getColumnType(ColumnType::STRING)); + $this->assertSame('text', $qb->getColumnType(ColumnType::TEXT)); + $this->assertSame('tinyint', $qb->getColumnType(ColumnType::TINYINT)); + $this->assertSame('smallint', $qb->getColumnType(ColumnType::SMALLINT)); + $this->assertSame('integer', $qb->getColumnType(ColumnType::INTEGER)); + $this->assertSame('bigint', $qb->getColumnType(ColumnType::BIGINT)); + $this->assertSame('float', $qb->getColumnType(ColumnType::FLOAT)); + $this->assertSame('double', $qb->getColumnType(ColumnType::DOUBLE)); + $this->assertSame('decimal', $qb->getColumnType(ColumnType::DECIMAL)); + $this->assertSame('datetime', $qb->getColumnType(ColumnType::DATETIME)); + $this->assertSame('timestamp', $qb->getColumnType(ColumnType::TIMESTAMP)); + $this->assertSame('time', $qb->getColumnType(ColumnType::TIME)); + $this->assertSame('date', $qb->getColumnType(ColumnType::DATE)); + $this->assertSame('binary', $qb->getColumnType(ColumnType::BINARY)); + $this->assertSame('boolean', $qb->getColumnType(ColumnType::BOOLEAN)); + $this->assertSame('money', $qb->getColumnType(ColumnType::MONEY)); + $this->assertSame('json', $qb->getColumnType(ColumnType::JSON)); } /** diff --git a/tests/AbstractSchemaTest.php b/tests/AbstractSchemaTest.php index 3059e606f..19324ab55 100644 --- a/tests/AbstractSchemaTest.php +++ b/tests/AbstractSchemaTest.php @@ -7,9 +7,7 @@ use PHPUnit\Framework\TestCase; use Yiisoft\Db\Command\DataType; use Yiisoft\Db\Schema\Builder\ColumnInterface; -use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Tests\Support\Assert; -use Yiisoft\Db\Tests\Support\Stub\ColumnSchema; use Yiisoft\Db\Tests\Support\TestTrait; use function fclose; @@ -28,14 +26,6 @@ public function testCreateColumnSchemaBuilder(): void $this->assertSame('string', $columnSchemaBuilder->getType()); } - public function testColumnSchemaDbTypecastWithEmptyCharType(): void - { - $columnSchema = new ColumnSchema('new'); - $columnSchema->type(SchemaInterface::TYPE_CHAR); - - $this->assertSame('', $columnSchema->dbTypecast('')); - } - public function testGetDefaultSchema(): void { $db = $this->getConnection(); diff --git a/tests/Common/CommonColumnSchemaBuilderTest.php b/tests/Common/CommonColumnSchemaBuilderTest.php index 9817a5f40..29daa8acd 100644 --- a/tests/Common/CommonColumnSchemaBuilderTest.php +++ b/tests/Common/CommonColumnSchemaBuilderTest.php @@ -5,10 +5,11 @@ namespace Yiisoft\Db\Tests\Common; use PHPUnit\Framework\TestCase; +use Yiisoft\Db\Constant\ColumnType; +use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Helper\DbUuidHelper; use Yiisoft\Db\Query\Query; -use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Tests\Support\TestTrait; use function array_shift; @@ -44,8 +45,8 @@ public function testUuid(): void } $db->createCommand()->createTable($tableName, [ - 'uuid_pk' => $schema->createColumn(SchemaInterface::TYPE_UUID_PK), - 'int_col' => $schema->createColumn(SchemaInterface::TYPE_INTEGER), + 'uuid_pk' => $schema->createColumn(PseudoType::UUID_PK), + 'int_col' => $schema->createColumn(ColumnType::INTEGER), ])->execute(); $tableSchema = $db->getTableSchema($tableName, true); $this->assertNotNull($tableSchema); diff --git a/tests/Common/CommonCommandTest.php b/tests/Common/CommonCommandTest.php index 3dcf8f15d..62f0b1dc5 100644 --- a/tests/Common/CommonCommandTest.php +++ b/tests/Common/CommonCommandTest.php @@ -6,6 +6,8 @@ use ReflectionException; use Throwable; +use Yiisoft\Db\Constant\ColumnType; +use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand; use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface; use Yiisoft\Db\Exception\Exception; @@ -21,7 +23,6 @@ use Yiisoft\Db\Query\Data\DataReaderInterface; use Yiisoft\Db\Query\Query; use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; -use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Tests\AbstractCommandTest; use Yiisoft\Db\Tests\Support\Assert; use Yiisoft\Db\Tests\Support\Stub\Column; @@ -72,11 +73,11 @@ public function testAddColumn(): void $db = $this->getConnection(true); $command = $db->createCommand(); - $command->addColumn('{{customer}}', '{{city}}', SchemaInterface::TYPE_STRING)->execute(); + $command->addColumn('{{customer}}', '{{city}}', ColumnType::STRING)->execute(); $this->assertTrue($db->getTableSchema('{{customer}}')->getColumn('city') !== null); $this->assertSame( - SchemaInterface::TYPE_STRING, + ColumnType::STRING, $db->getTableSchema('{{customer}}')->getColumn('city')->getType(), ); @@ -155,7 +156,7 @@ public function testAddDefaultValue(): void $command->dropTable('{{test_def}}')->execute(); } - $command->createTable('{{test_def}}', ['int1' => SchemaInterface::TYPE_INTEGER])->execute(); + $command->createTable('{{test_def}}', ['int1' => ColumnType::INTEGER])->execute(); $this->assertEmpty($schema->getTableDefaultValues('{{test_def}}', true)); @@ -545,8 +546,8 @@ public function testCreateTable(): void $command->createTable( '{{testCreateTable}}', [ - '[[id]]' => SchemaInterface::TYPE_PK, - '[[bar]]' => SchemaInterface::TYPE_INTEGER, + '[[id]]' => PseudoType::PK, + '[[bar]]' => ColumnType::INTEGER, '[[name]]' => (new Column('string(100)'))->notNull(), ], )->execute(); @@ -588,7 +589,7 @@ public function testCreateView(): void $command->createTable( '{{testCreateViewTable}}', - ['id' => SchemaInterface::TYPE_PK, 'bar' => SchemaInterface::TYPE_INTEGER], + ['id' => PseudoType::PK, 'bar' => ColumnType::INTEGER], )->execute(); $command->insert('{{testCreateViewTable}}', ['bar' => 1])->execute(); $command->insert('{{testCreateViewTable}}', ['bar' => 6])->execute(); @@ -720,9 +721,9 @@ public function testDropColumn(): void $command->createTable( '{{testDropColumn}}', [ - 'id' => SchemaInterface::TYPE_PK, - 'bar' => SchemaInterface::TYPE_INTEGER, - 'baz' => SchemaInterface::TYPE_INTEGER, + 'id' => PseudoType::PK, + 'bar' => ColumnType::INTEGER, + 'baz' => ColumnType::INTEGER, ], )->execute(); $command->dropColumn('{{testDropColumn}}', 'bar')->execute(); @@ -836,7 +837,7 @@ public function testDropForeignKey(): void $command->dropTable('{{test_fk}}')->execute(); } - $command->createTable('{{test_fk}}', ['id' => SchemaInterface::TYPE_PK, 'int1' => 'integer'])->execute(); + $command->createTable('{{test_fk}}', ['id' => PseudoType::PK, 'int1' => 'integer'])->execute(); $this->assertEmpty($schema->getTableForeignKeys('{{test_fk}}', true)); @@ -930,7 +931,7 @@ public function testDropTable(): void $command->dropTable('{{testDropTable}}')->execute(); } - $command->createTable('{{testDropTable}}', ['id' => SchemaInterface::TYPE_PK, 'foo' => 'integer'])->execute(); + $command->createTable('{{testDropTable}}', ['id' => PseudoType::PK, 'foo' => 'integer'])->execute(); $this->assertNotNull($schema->getTableSchema('{{testDropTable}}', true)); diff --git a/tests/Common/CommonQueryBuilderTest.php b/tests/Common/CommonQueryBuilderTest.php index d11f26ccf..238c8a36d 100644 --- a/tests/Common/CommonQueryBuilderTest.php +++ b/tests/Common/CommonQueryBuilderTest.php @@ -4,7 +4,7 @@ namespace Yiisoft\Db\Tests\Common; -use Yiisoft\Db\Schema\SchemaInterface; +use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Tests\AbstractQueryBuilderTest; use Yiisoft\Db\Tests\Provider\ColumnTypes; @@ -32,10 +32,10 @@ public function testCreateTableWithGetColumnTypes(): void foreach ($columnTypes as [$column, $expected]) { if ( !( - strncmp($column, SchemaInterface::TYPE_PK, 2) === 0 || - strncmp($column, SchemaInterface::TYPE_UPK, 3) === 0 || - strncmp($column, SchemaInterface::TYPE_BIGPK, 5) === 0 || - strncmp($column, SchemaInterface::TYPE_UBIGPK, 6) === 0 || + strncmp($column, PseudoType::PK, 2) === 0 || + strncmp($column, PseudoType::UPK, 3) === 0 || + strncmp($column, PseudoType::BIGPK, 5) === 0 || + strncmp($column, PseudoType::UBIGPK, 6) === 0 || str_starts_with(substr($column, -5), 'FIRST') ) ) { diff --git a/tests/Common/CommonSchemaTest.php b/tests/Common/CommonSchemaTest.php index 52bdb1ef1..1fad7be35 100644 --- a/tests/Common/CommonSchemaTest.php +++ b/tests/Common/CommonSchemaTest.php @@ -8,6 +8,7 @@ use PDO; use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Constraint\CheckConstraint; use Yiisoft\Db\Constraint\Constraint; use Yiisoft\Db\Constraint\DefaultValueConstraint; @@ -54,7 +55,7 @@ public function testColumnComment(): void $command->dropTable('testCommentTable')->execute(); } - $command->createTable('testCommentTable', ['bar' => SchemaInterface::TYPE_INTEGER,])->execute(); + $command->createTable('testCommentTable', ['bar' => ColumnType::INTEGER,])->execute(); $command->addCommentOnColumn('testCommentTable', 'bar', 'Test comment for column.')->execute(); $this->assertSame( diff --git a/tests/Db/Command/CommandTest.php b/tests/Db/Command/CommandTest.php index ebaa5802c..0ff505839 100644 --- a/tests/Db/Command/CommandTest.php +++ b/tests/Db/Command/CommandTest.php @@ -4,9 +4,10 @@ namespace Yiisoft\Db\Tests\Db\Command; +use Yiisoft\Db\Constant\ColumnType; +use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Schema\Builder\ColumnInterface; -use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Tests\AbstractCommandTest; use Yiisoft\Db\Tests\Support\Assert; use Yiisoft\Db\Tests\Support\DbHelper; @@ -163,7 +164,7 @@ public function testAlterColumn(): void $db = $this->getConnection(); $command = $db->createCommand(); - $sql = $command->alterColumn('table', 'column', SchemaInterface::TYPE_INTEGER)->getSql(); + $sql = $command->alterColumn('table', 'column', ColumnType::INTEGER)->getSql(); $this->assertSame( DbHelper::replaceQuotes( @@ -243,14 +244,14 @@ public function testCreateTable(): void ) CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB SQL; $columns = [ - 'id' => SchemaInterface::TYPE_PK, - 'name' => SchemaInterface::TYPE_STRING . '(255) NOT NULL', - 'email' => SchemaInterface::TYPE_STRING . '(255) NOT NULL', - 'address' => SchemaInterface::TYPE_STRING . '(255) NOT NULL', - 'status' => SchemaInterface::TYPE_INTEGER . ' NOT NULL', - 'profile_id' => SchemaInterface::TYPE_INTEGER . ' NOT NULL', - 'created_at' => SchemaInterface::TYPE_TIMESTAMP . ' NOT NULL', - 'updated_at' => SchemaInterface::TYPE_TIMESTAMP . ' NOT NULL', + 'id' => PseudoType::PK, + 'name' => ColumnType::STRING . '(255) NOT NULL', + 'email' => ColumnType::STRING . '(255) NOT NULL', + 'address' => ColumnType::STRING . '(255) NOT NULL', + 'status' => ColumnType::INTEGER . ' NOT NULL', + 'profile_id' => ColumnType::INTEGER . ' NOT NULL', + 'created_at' => ColumnType::TIMESTAMP . ' NOT NULL', + 'updated_at' => ColumnType::TIMESTAMP . ' NOT NULL', ]; $options = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB'; $sql = $command->createTable('test_table', $columns, $options)->getSql(); diff --git a/tests/Db/Schema/ColumnSchemaBuilderTest.php b/tests/Db/Schema/ColumnSchemaBuilderTest.php index 8b0a4457c..7c3fc7c32 100644 --- a/tests/Db/Schema/ColumnSchemaBuilderTest.php +++ b/tests/Db/Schema/ColumnSchemaBuilderTest.php @@ -5,8 +5,8 @@ namespace Yiisoft\Db\Tests\Db\Schema; use PHPUnit\Framework\TestCase; +use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Tests\Support\Stub\Column; /** @@ -264,7 +264,7 @@ public function testUnique(): void public function testUnsignedTypePk(): void { - $column = new Column(SchemaInterface::TYPE_PK); + $column = new Column(PseudoType::PK); $this->assertSame('pk', $column->asString()); $this->assertSame('upk', $column->unsigned()->asString()); @@ -272,7 +272,7 @@ public function testUnsignedTypePk(): void public function testUnsignedTypeUbigPk(): void { - $column = new Column(SchemaInterface::TYPE_BIGPK); + $column = new Column(PseudoType::BIGPK); $this->assertSame('bigpk', $column->asString()); $this->assertSame('ubigpk', $column->unsigned()->asString()); diff --git a/tests/Provider/ColumnFactoryProvider.php b/tests/Provider/ColumnFactoryProvider.php index 60062d881..8d46a5e24 100644 --- a/tests/Provider/ColumnFactoryProvider.php +++ b/tests/Provider/ColumnFactoryProvider.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Tests\Provider; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Schema\Column\BigIntColumnSchema; use Yiisoft\Db\Schema\Column\BinaryColumnSchema; use Yiisoft\Db\Schema\Column\BooleanColumnSchema; @@ -17,37 +18,39 @@ class ColumnFactoryProvider public static function definitions(): array { return [ - '' => ['', 'string', StringColumnSchema::class], - 'text' => ['text', 'text', StringColumnSchema::class], - 'text NOT NULL' => ['text NOT NULL', 'text', StringColumnSchema::class, ['getExtra' => 'NOT NULL']], - 'char(1)' => ['char(1)', 'char', StringColumnSchema::class, ['getSize' => 1]], - 'decimal(10,2)' => ['decimal(10,2)', 'decimal', DoubleColumnSchema::class, ['getPrecision' => 10, 'getScale' => 2]], - 'bigint UNSIGNED' => ['bigint UNSIGNED', 'bigint', BigIntColumnSchema::class, ['isUnsigned' => true]], + // definition, expected type, expected instance of, expected column method results + '' => ['', ColumnType::STRING, StringColumnSchema::class], + 'text' => ['text', ColumnType::TEXT, StringColumnSchema::class], + 'text NOT NULL' => ['text NOT NULL', ColumnType::TEXT, StringColumnSchema::class], + 'char(1)' => ['char(1)', ColumnType::CHAR, StringColumnSchema::class], + 'decimal(10,2)' => ['decimal(10,2)', ColumnType::DECIMAL, DoubleColumnSchema::class], + 'bigint UNSIGNED' => ['bigint UNSIGNED', ColumnType::BIGINT, BigIntColumnSchema::class], ]; } public static function types(): array { return [ - 'uuid' => ['uuid', 'uuid', StringColumnSchema::class], - 'char' => ['char', 'char', StringColumnSchema::class], - 'string' => ['string', 'string', StringColumnSchema::class], - 'text' => ['text', 'text', StringColumnSchema::class], - 'binary' => ['binary', 'binary', BinaryColumnSchema::class], - 'boolean' => ['boolean', 'boolean', BooleanColumnSchema::class], - 'tinyint' => ['tinyint', 'tinyint', IntegerColumnSchema::class], - 'smallint' => ['smallint', 'smallint', IntegerColumnSchema::class], - 'integer' => ['integer', 'integer', IntegerColumnSchema::class], - 'bigint' => ['bigint', 'bigint', IntegerColumnSchema::class], - 'float' => ['float', 'float', DoubleColumnSchema::class], - 'double' => ['double', 'double', DoubleColumnSchema::class], - 'decimal' => ['decimal', 'decimal', DoubleColumnSchema::class], - 'money' => ['money', 'money', StringColumnSchema::class], - 'datetime' => ['datetime', 'datetime', StringColumnSchema::class], - 'timestamp' => ['timestamp', 'timestamp', StringColumnSchema::class], - 'time' => ['time', 'time', StringColumnSchema::class], - 'date' => ['date', 'date', StringColumnSchema::class], - 'json' => ['json', 'json', JsonColumnSchema::class], + // type, expected type, expected instance of + 'uuid' => [ColumnType::UUID, ColumnType::UUID, StringColumnSchema::class], + 'char' => [ColumnType::CHAR, ColumnType::CHAR, StringColumnSchema::class], + 'string' => [ColumnType::STRING, ColumnType::STRING, StringColumnSchema::class], + 'text' => [ColumnType::TEXT, ColumnType::TEXT, StringColumnSchema::class], + 'binary' => [ColumnType::BINARY, ColumnType::BINARY, BinaryColumnSchema::class], + 'boolean' => [ColumnType::BOOLEAN, ColumnType::BOOLEAN, BooleanColumnSchema::class], + 'tinyint' => [ColumnType::TINYINT, ColumnType::TINYINT, IntegerColumnSchema::class], + 'smallint' => [ColumnType::SMALLINT, ColumnType::SMALLINT, IntegerColumnSchema::class], + 'integer' => [ColumnType::INTEGER, ColumnType::INTEGER, IntegerColumnSchema::class], + 'bigint' => [ColumnType::BIGINT, ColumnType::BIGINT, IntegerColumnSchema::class], + 'float' => [ColumnType::FLOAT, ColumnType::FLOAT, DoubleColumnSchema::class], + 'double' => [ColumnType::DOUBLE, ColumnType::DOUBLE, DoubleColumnSchema::class], + 'decimal' => [ColumnType::DECIMAL, ColumnType::DECIMAL, DoubleColumnSchema::class], + 'money' => [ColumnType::MONEY, ColumnType::MONEY, StringColumnSchema::class], + 'datetime' => [ColumnType::DATETIME, ColumnType::DATETIME, StringColumnSchema::class], + 'timestamp' => [ColumnType::TIMESTAMP, ColumnType::TIMESTAMP, StringColumnSchema::class], + 'time' => [ColumnType::TIME, ColumnType::TIME, StringColumnSchema::class], + 'date' => [ColumnType::DATE, ColumnType::DATE, StringColumnSchema::class], + 'json' => [ColumnType::JSON, ColumnType::JSON, JsonColumnSchema::class], ]; } } diff --git a/tests/Provider/ColumnSchemaBuilderProvider.php b/tests/Provider/ColumnSchemaBuilderProvider.php index 8e3de4780..1ffc3d907 100644 --- a/tests/Provider/ColumnSchemaBuilderProvider.php +++ b/tests/Provider/ColumnSchemaBuilderProvider.php @@ -4,8 +4,9 @@ namespace Yiisoft\Db\Tests\Provider; +use Yiisoft\Db\Constant\ColumnType; +use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Tests\Support\DbHelper; class ColumnSchemaBuilderProvider @@ -15,9 +16,9 @@ class ColumnSchemaBuilderProvider public static function types(): array { return [ - ['integer NULL DEFAULT NULL', SchemaInterface::TYPE_INTEGER, null, [['unsigned'], ['null']]], - ['integer(10)', SchemaInterface::TYPE_INTEGER, 10, [['unsigned']]], - ['integer(10)', SchemaInterface::TYPE_INTEGER, 10, [['comment', 'test']]], + ['integer NULL DEFAULT NULL', ColumnType::INTEGER, null, [['unsigned'], ['null']]], + ['integer(10)', ColumnType::INTEGER, 10, [['unsigned']]], + ['integer(10)', ColumnType::INTEGER, 10, [['comment', 'test']]], ['timestamp() WITH TIME ZONE NOT NULL', 'timestamp() WITH TIME ZONE', null, [['notNull']]], [ 'timestamp() WITH TIME ZONE DEFAULT NOW()', @@ -33,43 +34,43 @@ public static function createColumnTypes(): array return [ 'integer' => [ Dbhelper::replaceQuotes('[[column]] integer', static::$driverName), - SchemaInterface::TYPE_INTEGER, + ColumnType::INTEGER, null, [], ], 'uuid' => [ '', - SchemaInterface::TYPE_UUID, + ColumnType::UUID, null, [], ], 'uuid not null' => [ '', - SchemaInterface::TYPE_UUID, + ColumnType::UUID, null, [['notNull']], ], 'uuid with default' => [ '', - SchemaInterface::TYPE_UUID, + ColumnType::UUID, null, [['defaultValue', '875343b3-6bd0-4bec-81bb-aa68bb52d945']], ], 'uuid pk' => [ '', - SchemaInterface::TYPE_UUID_PK, + PseudoType::UUID_PK, null, [], ], 'uuid pk not null' => [ '', - SchemaInterface::TYPE_UUID_PK, + PseudoType::UUID_PK, null, [['notNull']], ], 'uuid pk not null with default' => [ '', - SchemaInterface::TYPE_UUID_PK, + PseudoType::UUID_PK, null, [], ], diff --git a/tests/Provider/ColumnSchemaProvider.php b/tests/Provider/ColumnSchemaProvider.php index 4ae2a12a2..83bf35b71 100644 --- a/tests/Provider/ColumnSchemaProvider.php +++ b/tests/Provider/ColumnSchemaProvider.php @@ -7,6 +7,7 @@ use PDO; use stdClass; use Yiisoft\Db\Command\Param; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Expression\JsonExpression; use Yiisoft\Db\Constant\PhpType; @@ -18,7 +19,6 @@ use Yiisoft\Db\Schema\Column\IntegerColumnSchema; use Yiisoft\Db\Schema\Column\JsonColumnSchema; use Yiisoft\Db\Schema\Column\StringColumnSchema; -use Yiisoft\Db\Schema\SchemaInterface; use function fopen; @@ -28,14 +28,14 @@ public static function predefinedTypes(): array { return [ // [class, type, phpType] - 'integer' => [IntegerColumnSchema::class, SchemaInterface::TYPE_INTEGER, PhpType::INT], - 'bigint' => [BigIntColumnSchema::class, SchemaInterface::TYPE_BIGINT, PhpType::STRING], - 'double' => [DoubleColumnSchema::class, SchemaInterface::TYPE_DOUBLE, PhpType::FLOAT], - 'string' => [StringColumnSchema::class, SchemaInterface::TYPE_STRING, PhpType::STRING], - 'binary' => [BinaryColumnSchema::class, SchemaInterface::TYPE_BINARY, PhpType::MIXED], - 'bit' => [BitColumnSchema::class, SchemaInterface::TYPE_BIT, PhpType::INT], - 'boolean' => [BooleanColumnSchema::class, SchemaInterface::TYPE_BOOLEAN, PhpType::BOOL], - 'json' => [JsonColumnSchema::class, SchemaInterface::TYPE_JSON, PhpType::MIXED], + 'integer' => [IntegerColumnSchema::class, ColumnType::INTEGER, PhpType::INT], + 'bigint' => [BigIntColumnSchema::class, ColumnType::BIGINT, PhpType::STRING], + 'double' => [DoubleColumnSchema::class, ColumnType::DOUBLE, PhpType::FLOAT], + 'string' => [StringColumnSchema::class, ColumnType::STRING, PhpType::STRING], + 'binary' => [BinaryColumnSchema::class, ColumnType::BINARY, PhpType::MIXED], + 'bit' => [BitColumnSchema::class, ColumnType::BIT, PhpType::INT], + 'boolean' => [BooleanColumnSchema::class, ColumnType::BOOLEAN, PhpType::BOOL], + 'json' => [JsonColumnSchema::class, ColumnType::JSON, PhpType::MIXED], ]; } diff --git a/tests/Provider/ColumnTypes.php b/tests/Provider/ColumnTypes.php index 2cd4bffc1..2d9ba399d 100644 --- a/tests/Provider/ColumnTypes.php +++ b/tests/Provider/ColumnTypes.php @@ -4,8 +4,9 @@ namespace Yiisoft\Db\Tests\Provider; +use Yiisoft\Db\Constant\ColumnType; +use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface; -use Yiisoft\Db\Schema\SchemaInterface; use function array_key_exists; use function array_values; @@ -24,7 +25,7 @@ public function getColumnTypes(): array { $items = [ '$this->bigInteger()' => [ - SchemaInterface::TYPE_BIGINT, + ColumnType::BIGINT, [ 'mysql' => 'bigint(20)', 'pgsql' => 'bigint', @@ -34,7 +35,7 @@ public function getColumnTypes(): array ], ], '$this->bigInteger()->notNull()' => [ - SchemaInterface::TYPE_BIGINT . ' NOT NULL', + ColumnType::BIGINT . ' NOT NULL', [ 'mysql' => 'bigint(20) NOT NULL', 'pgsql' => 'bigint NOT NULL', @@ -44,7 +45,7 @@ public function getColumnTypes(): array ], ], '$this->bigInteger()->check(\'value > 5\')' => [ - SchemaInterface::TYPE_BIGINT . ' CHECK (value > 5)', + ColumnType::BIGINT . ' CHECK (value > 5)', [ 'mysql' => 'bigint(20) CHECK (value > 5)', 'pgsql' => 'bigint CHECK (value > 5)', @@ -54,7 +55,7 @@ public function getColumnTypes(): array ], ], '$this->bigInteger(8)' => [ - SchemaInterface::TYPE_BIGINT . '(8)', + ColumnType::BIGINT . '(8)', [ 'mysql' => 'bigint(8)', 'pgsql' => 'bigint', @@ -64,7 +65,7 @@ public function getColumnTypes(): array ], ], '$this->bigInteger(8)->check(\'value > 5\')' => [ - SchemaInterface::TYPE_BIGINT . '(8) CHECK (value > 5)', + ColumnType::BIGINT . '(8) CHECK (value > 5)', [ 'mysql' => 'bigint(8) CHECK (value > 5)', 'pgsql' => 'bigint CHECK (value > 5)', @@ -74,7 +75,7 @@ public function getColumnTypes(): array ], ], '$this->bigPrimaryKey()' => [ - SchemaInterface::TYPE_BIGPK, + PseudoType::BIGPK, [ 'mysql' => 'bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY', 'pgsql' => 'bigserial NOT NULL PRIMARY KEY', @@ -82,7 +83,7 @@ public function getColumnTypes(): array ], ], '$this->binary()' => [ - SchemaInterface::TYPE_BINARY, + ColumnType::BINARY, [ 'mysql' => 'blob', 'pgsql' => 'bytea', @@ -92,7 +93,7 @@ public function getColumnTypes(): array ], ], '$this->boolean()->notNull()->defaultValue(1)' => [ - SchemaInterface::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', + ColumnType::BOOLEAN . ' NOT NULL DEFAULT 1', [ 'mysql' => 'bit(1) NOT NULL DEFAULT 1', 'sqlite' => 'boolean NOT NULL DEFAULT 1', @@ -100,13 +101,13 @@ public function getColumnTypes(): array ], ], '$this->boolean()->notNull()->defaultValue(true)' => [ - SchemaInterface::TYPE_BOOLEAN . ' NOT NULL DEFAULT TRUE', + ColumnType::BOOLEAN . ' NOT NULL DEFAULT TRUE', [ 'pgsql' => 'boolean NOT NULL DEFAULT TRUE', ], ], '$this->boolean()' => [ - SchemaInterface::TYPE_BOOLEAN, + ColumnType::BOOLEAN, [ 'mysql' => 'bit(1)', 'pgsql' => 'boolean', @@ -116,20 +117,20 @@ public function getColumnTypes(): array ], ], '$this->char()->check(\'value LIKE \\\'test%\\\'\')' => [ - SchemaInterface::TYPE_CHAR . ' CHECK (value LIKE \'test%\')', + ColumnType::CHAR . ' CHECK (value LIKE \'test%\')', [ 'pgsql' => 'char(1) CHECK (value LIKE \'test%\')', 'mysql' => 'char(1) CHECK (value LIKE \'test%\')', ], ], '$this->char()->check(\'value LIKE "test%"\')' => [ - SchemaInterface::TYPE_CHAR . ' CHECK (value LIKE "test%")', + ColumnType::CHAR . ' CHECK (value LIKE "test%")', [ 'sqlite' => 'char(1) CHECK (value LIKE "test%")', ], ], '$this->char()->notNull()' => [ - SchemaInterface::TYPE_CHAR . ' NOT NULL', + ColumnType::CHAR . ' NOT NULL', [ 'mysql' => 'char(1) NOT NULL', 'pgsql' => 'char(1) NOT NULL', @@ -138,25 +139,25 @@ public function getColumnTypes(): array ], ], '$this->char(6)->check(\'value LIKE "test%"\')' => [ - SchemaInterface::TYPE_CHAR . '(6) CHECK (value LIKE "test%")', + ColumnType::CHAR . '(6) CHECK (value LIKE "test%")', [ 'sqlite' => 'char(6) CHECK (value LIKE "test%")', ], ], '$this->char(6)->check(\'value LIKE \\\'test%\\\'\')' => [ - SchemaInterface::TYPE_CHAR . '(6) CHECK (value LIKE \'test%\')', + ColumnType::CHAR . '(6) CHECK (value LIKE \'test%\')', [ 'mysql' => 'char(6) CHECK (value LIKE \'test%\')', ], ], '$this->char(6)->unsigned()' => [ - SchemaInterface::TYPE_CHAR . '(6)', + ColumnType::CHAR . '(6)', [ 'pgsql' => 'char(6)', ], ], '$this->char(6)' => [ - SchemaInterface::TYPE_CHAR . '(6)', + ColumnType::CHAR . '(6)', [ 'mysql' => 'char(6)', 'pgsql' => 'char(6)', @@ -165,7 +166,7 @@ public function getColumnTypes(): array ], ], '$this->char()' => [ - SchemaInterface::TYPE_CHAR, + ColumnType::CHAR, [ 'mysql' => 'char(1)', 'pgsql' => 'char(1)', @@ -174,7 +175,7 @@ public function getColumnTypes(): array ], ], '$this->date()->notNull()' => [ - SchemaInterface::TYPE_DATE . ' NOT NULL', + ColumnType::DATE . ' NOT NULL', [ 'pgsql' => 'date NOT NULL', 'sqlite' => 'date NOT NULL', @@ -183,7 +184,7 @@ public function getColumnTypes(): array ], ], '$this->date()' => [ - SchemaInterface::TYPE_DATE, + ColumnType::DATE, [ 'mysql' => 'date', 'pgsql' => 'date', @@ -193,7 +194,7 @@ public function getColumnTypes(): array ], ], '$this->dateTime()->notNull()' => [ - SchemaInterface::TYPE_DATETIME . ' NOT NULL', + ColumnType::DATETIME . ' NOT NULL', [ 'mysql' => 'datetime(0) NOT NULL', 'pgsql' => 'timestamp(0) NOT NULL', @@ -203,7 +204,7 @@ public function getColumnTypes(): array ], ], '$this->dateTime()' => [ - SchemaInterface::TYPE_DATETIME, + ColumnType::DATETIME, [ 'mysql' => 'datetime(0)', 'pgsql' => 'timestamp(0)', @@ -213,7 +214,7 @@ public function getColumnTypes(): array ], ], '$this->decimal()->check(\'value > 5.6\')' => [ - SchemaInterface::TYPE_DECIMAL . ' CHECK (value > 5.6)', + ColumnType::DECIMAL . ' CHECK (value > 5.6)', [ 'mysql' => 'decimal(10,0) CHECK (value > 5.6)', 'pgsql' => 'numeric(10,0) CHECK (value > 5.6)', @@ -223,7 +224,7 @@ public function getColumnTypes(): array ], ], '$this->decimal()->notNull()' => [ - SchemaInterface::TYPE_DECIMAL . ' NOT NULL', + ColumnType::DECIMAL . ' NOT NULL', [ 'mysql' => 'decimal(10,0) NOT NULL', 'pgsql' => 'numeric(10,0) NOT NULL', @@ -233,7 +234,7 @@ public function getColumnTypes(): array ], ], '$this->decimal(12, 4)->check(\'value > 5.6\')' => [ - SchemaInterface::TYPE_DECIMAL . '(12,4) CHECK (value > 5.6)', + ColumnType::DECIMAL . '(12,4) CHECK (value > 5.6)', [ 'mysql' => 'decimal(12,4) CHECK (value > 5.6)', 'pgsql' => 'numeric(12,4) CHECK (value > 5.6)', @@ -243,7 +244,7 @@ public function getColumnTypes(): array ], ], '$this->decimal(12, 4)' => [ - SchemaInterface::TYPE_DECIMAL . '(12,4)', + ColumnType::DECIMAL . '(12,4)', [ 'mysql' => 'decimal(12,4)', 'pgsql' => 'numeric(12,4)', @@ -253,7 +254,7 @@ public function getColumnTypes(): array ], ], '$this->decimal()' => [ - SchemaInterface::TYPE_DECIMAL, + ColumnType::DECIMAL, [ 'mysql' => 'decimal(10,0)', 'pgsql' => 'numeric(10,0)', @@ -263,7 +264,7 @@ public function getColumnTypes(): array ], ], '$this->double()->check(\'value > 5.6\')' => [ - SchemaInterface::TYPE_DOUBLE . ' CHECK (value > 5.6)', + ColumnType::DOUBLE . ' CHECK (value > 5.6)', [ 'mysql' => 'double CHECK (value > 5.6)', 'pgsql' => 'double precision CHECK (value > 5.6)', @@ -273,7 +274,7 @@ public function getColumnTypes(): array ], ], '$this->double()->notNull()' => [ - SchemaInterface::TYPE_DOUBLE . ' NOT NULL', + ColumnType::DOUBLE . ' NOT NULL', [ 'mysql' => 'double NOT NULL', 'pgsql' => 'double precision NOT NULL', @@ -283,7 +284,7 @@ public function getColumnTypes(): array ], ], '$this->double(16)->check(\'value > 5.6\')' => [ - SchemaInterface::TYPE_DOUBLE . '(16) CHECK (value > 5.6)', + ColumnType::DOUBLE . '(16) CHECK (value > 5.6)', [ 'mysql' => 'double CHECK (value > 5.6)', 'pgsql' => 'double precision CHECK (value > 5.6)', @@ -293,7 +294,7 @@ public function getColumnTypes(): array ], ], '$this->double(16)' => [ - SchemaInterface::TYPE_DOUBLE . '(16)', + ColumnType::DOUBLE . '(16)', [ 'mysql' => 'double', 'sqlite' => 'double', @@ -302,7 +303,7 @@ public function getColumnTypes(): array ], ], '$this->double()' => [ - SchemaInterface::TYPE_DOUBLE, + ColumnType::DOUBLE, [ 'mysql' => 'double', 'pgsql' => 'double precision', @@ -312,7 +313,7 @@ public function getColumnTypes(): array ], ], '$this->float()->check(\'value > 5.6\')' => [ - SchemaInterface::TYPE_FLOAT . ' CHECK (value > 5.6)', + ColumnType::FLOAT . ' CHECK (value > 5.6)', [ 'mysql' => 'float CHECK (value > 5.6)', 'pgsql' => 'double precision CHECK (value > 5.6)', @@ -322,7 +323,7 @@ public function getColumnTypes(): array ], ], '$this->float()->notNull()' => [ - SchemaInterface::TYPE_FLOAT . ' NOT NULL', + ColumnType::FLOAT . ' NOT NULL', [ 'mysql' => 'float NOT NULL', 'pgsql' => 'double precision NOT NULL', @@ -332,7 +333,7 @@ public function getColumnTypes(): array ], ], '$this->float(16)->check(\'value > 5.6\')' => [ - SchemaInterface::TYPE_FLOAT . '(16) CHECK (value > 5.6)', + ColumnType::FLOAT . '(16) CHECK (value > 5.6)', [ 'mysql' => 'float CHECK (value > 5.6)', 'pgsql' => 'double precision CHECK (value > 5.6)', @@ -342,7 +343,7 @@ public function getColumnTypes(): array ], ], '$this->float(16)' => [ - SchemaInterface::TYPE_FLOAT . '(16)', + ColumnType::FLOAT . '(16)', [ 'mysql' => 'float', 'sqlite' => 'float', @@ -351,7 +352,7 @@ public function getColumnTypes(): array ], ], '$this->float()' => [ - SchemaInterface::TYPE_FLOAT, + ColumnType::FLOAT, [ 'mysql' => 'float', 'pgsql' => 'double precision', @@ -361,7 +362,7 @@ public function getColumnTypes(): array ], ], '$this->integer()->check(\'value > 5\')' => [ - SchemaInterface::TYPE_INTEGER . ' CHECK (value > 5)', + ColumnType::INTEGER . ' CHECK (value > 5)', [ 'mysql' => 'int(11) CHECK (value > 5)', 'pgsql' => 'integer CHECK (value > 5)', @@ -371,7 +372,7 @@ public function getColumnTypes(): array ], ], '$this->integer()->notNull()' => [ - SchemaInterface::TYPE_INTEGER . ' NOT NULL', + ColumnType::INTEGER . ' NOT NULL', [ 'mysql' => 'int(11) NOT NULL', 'pgsql' => 'integer NOT NULL', @@ -381,7 +382,7 @@ public function getColumnTypes(): array ], ], '$this->integer(8)->check(\'value > 5\')' => [ - SchemaInterface::TYPE_INTEGER . '(8) CHECK (value > 5)', + ColumnType::INTEGER . '(8) CHECK (value > 5)', [ 'mysql' => 'int(8) CHECK (value > 5)', 'pgsql' => 'integer CHECK (value > 5)', @@ -391,13 +392,13 @@ public function getColumnTypes(): array ], ], '$this->integer(8)->unsigned()' => [ - SchemaInterface::TYPE_INTEGER . '(8)', + ColumnType::INTEGER . '(8)', [ 'pgsql' => 'integer', ], ], '$this->integer(8)' => [ - SchemaInterface::TYPE_INTEGER . '(8)', + ColumnType::INTEGER . '(8)', [ 'mysql' => 'int(8)', 'pgsql' => 'integer', @@ -407,7 +408,7 @@ public function getColumnTypes(): array ], ], '$this->integer()' => [ - SchemaInterface::TYPE_INTEGER, + ColumnType::INTEGER, [ 'mysql' => 'int(11)', 'pgsql' => 'integer', @@ -417,7 +418,7 @@ public function getColumnTypes(): array ], ], '$this->money()->check(\'value > 0.0\')' => [ - SchemaInterface::TYPE_MONEY . ' CHECK (value > 0.0)', + ColumnType::MONEY . ' CHECK (value > 0.0)', [ 'mysql' => 'decimal(19,4) CHECK (value > 0.0)', 'pgsql' => 'numeric(19,4) CHECK (value > 0.0)', @@ -427,7 +428,7 @@ public function getColumnTypes(): array ], ], '$this->money()->notNull()' => [ - SchemaInterface::TYPE_MONEY . ' NOT NULL', + ColumnType::MONEY . ' NOT NULL', [ 'mysql' => 'decimal(19,4) NOT NULL', 'pgsql' => 'numeric(19,4) NOT NULL', @@ -437,7 +438,7 @@ public function getColumnTypes(): array ], ], '$this->money(16, 2)->check(\'value > 0.0\')' => [ - SchemaInterface::TYPE_MONEY . '(16,2) CHECK (value > 0.0)', + ColumnType::MONEY . '(16,2) CHECK (value > 0.0)', [ 'mysql' => 'decimal(16,2) CHECK (value > 0.0)', 'pgsql' => 'numeric(16,2) CHECK (value > 0.0)', @@ -447,7 +448,7 @@ public function getColumnTypes(): array ], ], '$this->money(16, 2)' => [ - SchemaInterface::TYPE_MONEY . '(16,2)', + ColumnType::MONEY . '(16,2)', [ 'mysql' => 'decimal(16,2)', 'pgsql' => 'numeric(16,2)', @@ -457,7 +458,7 @@ public function getColumnTypes(): array ], ], '$this->money()' => [ - SchemaInterface::TYPE_MONEY, + ColumnType::MONEY, [ 'mysql' => 'decimal(19,4)', 'pgsql' => 'numeric(19,4)', @@ -467,7 +468,7 @@ public function getColumnTypes(): array ], ], '$this->primaryKey()->check(\'value > 5\')' => [ - SchemaInterface::TYPE_PK . ' CHECK (value > 5)', + PseudoType::PK . ' CHECK (value > 5)', [ 'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)', 'pgsql' => 'serial NOT NULL PRIMARY KEY CHECK (value > 5)', @@ -477,21 +478,21 @@ public function getColumnTypes(): array ], ], '$this->primaryKey(8)->check(\'value > 5\')' => [ - SchemaInterface::TYPE_PK . '(8) CHECK (value > 5)', + PseudoType::PK . '(8) CHECK (value > 5)', [ 'mysql' => 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY CHECK (value > 5)', 'oci' => 'NUMBER(8) GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY CHECK (value > 5)', ], ], '$this->primaryKey(8)' => [ - SchemaInterface::TYPE_PK . '(8)', + PseudoType::PK . '(8)', [ 'mysql' => 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY', 'oci' => 'NUMBER(8) GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY', ], ], '$this->primaryKey()' => [ - SchemaInterface::TYPE_PK, + PseudoType::PK, [ 'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY', 'pgsql' => 'serial NOT NULL PRIMARY KEY', @@ -501,7 +502,7 @@ public function getColumnTypes(): array ], ], '$this->tinyInteger(2)' => [ - SchemaInterface::TYPE_TINYINT . '(2)', + ColumnType::TINYINT . '(2)', [ 'mysql' => 'tinyint(2)', 'pgsql' => 'smallint', @@ -511,14 +512,14 @@ public function getColumnTypes(): array ], ], '$this->tinyInteger()->unsigned()' => [ - SchemaInterface::TYPE_TINYINT . ' UNSIGNED', + ColumnType::TINYINT . ' UNSIGNED', [ 'mysql' => 'tinyint(3) UNSIGNED', 'sqlite' => 'tinyint UNSIGNED', ], ], '$this->tinyInteger()' => [ - SchemaInterface::TYPE_TINYINT, + ColumnType::TINYINT, [ 'mysql' => 'tinyint(3)', 'pgsql' => 'smallint', @@ -528,7 +529,7 @@ public function getColumnTypes(): array ], ], '$this->smallInteger(8)' => [ - SchemaInterface::TYPE_SMALLINT . '(8)', + ColumnType::SMALLINT . '(8)', [ 'mysql' => 'smallint(8)', 'pgsql' => 'smallint', @@ -538,7 +539,7 @@ public function getColumnTypes(): array ], ], '$this->smallInteger()' => [ - SchemaInterface::TYPE_SMALLINT, + ColumnType::SMALLINT, [ 'mysql' => 'smallint(6)', 'pgsql' => 'smallint', @@ -548,7 +549,7 @@ public function getColumnTypes(): array ], ], '$this->string()->check("value LIKE \'test%\'")' => [ - SchemaInterface::TYPE_STRING . " CHECK (value LIKE 'test%')", + ColumnType::STRING . " CHECK (value LIKE 'test%')", [ 'mysql' => "varchar(255) CHECK (value LIKE 'test%')", 'sqlite' => "varchar(255) CHECK (value LIKE 'test%')", @@ -556,14 +557,14 @@ public function getColumnTypes(): array ], ], '$this->string()->check(\'value LIKE \\\'test%\\\'\')' => [ - SchemaInterface::TYPE_STRING . ' CHECK (value LIKE \'test%\')', + ColumnType::STRING . ' CHECK (value LIKE \'test%\')', [ 'pgsql' => 'varchar(255) CHECK (value LIKE \'test%\')', 'oci' => 'VARCHAR2(255) CHECK (value LIKE \'test%\')', ], ], '$this->string()->notNull()' => [ - SchemaInterface::TYPE_STRING . ' NOT NULL', + ColumnType::STRING . ' NOT NULL', [ 'mysql' => 'varchar(255) NOT NULL', 'pgsql' => 'varchar(255) NOT NULL', @@ -573,7 +574,7 @@ public function getColumnTypes(): array ], ], '$this->string(32)->check("value LIKE \'test%\'")' => [ - SchemaInterface::TYPE_STRING . "(32) CHECK (value LIKE 'test%')", + ColumnType::STRING . "(32) CHECK (value LIKE 'test%')", [ 'mysql' => "varchar(32) CHECK (value LIKE 'test%')", 'sqlite' => "varchar(32) CHECK (value LIKE 'test%')", @@ -581,14 +582,14 @@ public function getColumnTypes(): array ], ], '$this->string(32)->check(\'value LIKE \\\'test%\\\'\')' => [ - SchemaInterface::TYPE_STRING . '(32) CHECK (value LIKE \'test%\')', + ColumnType::STRING . '(32) CHECK (value LIKE \'test%\')', [ 'pgsql' => 'varchar(32) CHECK (value LIKE \'test%\')', 'oci' => 'VARCHAR2(32) CHECK (value LIKE \'test%\')', ], ], '$this->string(32)' => [ - SchemaInterface::TYPE_STRING . '(32)', + ColumnType::STRING . '(32)', [ 'mysql' => 'varchar(32)', 'pgsql' => 'varchar(32)', @@ -598,7 +599,7 @@ public function getColumnTypes(): array ], ], '$this->string()' => [ - SchemaInterface::TYPE_STRING, + ColumnType::STRING, [ 'mysql' => 'varchar(255)', 'pgsql' => 'varchar(255)', @@ -608,7 +609,7 @@ public function getColumnTypes(): array ], ], '$this->text()->check("value LIKE \'test%\'")' => [ - SchemaInterface::TYPE_TEXT . " CHECK (value LIKE 'test%')", + ColumnType::TEXT . " CHECK (value LIKE 'test%')", [ 'mysql' => "text CHECK (value LIKE 'test%')", 'sqlite' => "text CHECK (value LIKE 'test%')", @@ -616,7 +617,7 @@ public function getColumnTypes(): array ], ], '$this->text()->notNull()' => [ - SchemaInterface::TYPE_TEXT . ' NOT NULL', + ColumnType::TEXT . ' NOT NULL', [ 'mysql' => 'text NOT NULL', 'pgsql' => 'text NOT NULL', @@ -626,14 +627,14 @@ public function getColumnTypes(): array ], ], '$this->text()->check(\'value LIKE \\\'test%\\\'\')' => [ - SchemaInterface::TYPE_TEXT . ' CHECK (value LIKE \'test%\')', + ColumnType::TEXT . ' CHECK (value LIKE \'test%\')', [ 'pgsql' => 'text CHECK (value LIKE \'test%\')', 'oci' => 'CLOB CHECK (value LIKE \'test%\')', ], ], '$this->text()' => [ - SchemaInterface::TYPE_TEXT, + ColumnType::TEXT, [ 'mysql' => 'text', 'pgsql' => 'text', @@ -643,7 +644,7 @@ public function getColumnTypes(): array ], ], '$this->time()->notNull()' => [ - SchemaInterface::TYPE_TIME . ' NOT NULL', + ColumnType::TIME . ' NOT NULL', [ 'mysql' => 'time(0) NOT NULL', 'pgsql' => 'time(0) NOT NULL', @@ -653,7 +654,7 @@ public function getColumnTypes(): array ], ], '$this->time()' => [ - SchemaInterface::TYPE_TIME, + ColumnType::TIME, [ 'mysql' => 'time(0)', 'pgsql' => 'time(0)', @@ -663,7 +664,7 @@ public function getColumnTypes(): array ], ], '$this->timestamp()->notNull()' => [ - SchemaInterface::TYPE_TIMESTAMP . ' NOT NULL', + ColumnType::TIMESTAMP . ' NOT NULL', [ 'mysql' => 'timestamp(0) NOT NULL', 'pgsql' => 'timestamp(0) NOT NULL', @@ -673,7 +674,7 @@ public function getColumnTypes(): array ], ], '$this->timestamp()->defaultValue(null)' => [ - SchemaInterface::TYPE_TIMESTAMP . ' NULL DEFAULT NULL', + ColumnType::TIMESTAMP . ' NULL DEFAULT NULL', [ 'mysql' => 'timestamp(0) NULL DEFAULT NULL', 'pgsql' => 'timestamp(0) NULL DEFAULT NULL', @@ -682,14 +683,14 @@ public function getColumnTypes(): array ], ], '$this->timestamp(4)' => [ - SchemaInterface::TYPE_TIMESTAMP . '(4)', + ColumnType::TIMESTAMP . '(4)', [ 'pgsql' => 'timestamp(4)', 'oci' => 'TIMESTAMP(4)', ], ], '$this->timestamp()' => [ - SchemaInterface::TYPE_TIMESTAMP, + ColumnType::TIMESTAMP, [ /** * MySQL has its own TIMESTAMP test realization. @@ -703,7 +704,7 @@ public function getColumnTypes(): array ], ], '$this->primaryKey()->unsigned()' => [ - SchemaInterface::TYPE_UPK, + PseudoType::UPK, [ 'mysql' => 'int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', 'pgsql' => 'serial NOT NULL PRIMARY KEY', @@ -711,7 +712,7 @@ public function getColumnTypes(): array ], ], '$this->bigPrimaryKey()->unsigned()' => [ - SchemaInterface::TYPE_UBIGPK, + PseudoType::UBIGPK, [ 'mysql' => 'bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', 'pgsql' => 'bigserial NOT NULL PRIMARY KEY', @@ -719,21 +720,21 @@ public function getColumnTypes(): array ], ], '$this->integer()->comment(\'test comment\')' => [ - SchemaInterface::TYPE_INTEGER . " COMMENT 'test comment'", + ColumnType::INTEGER . " COMMENT 'test comment'", [ 'mysql' => "int(11) COMMENT 'test comment'", 'sqlsrv' => 'int', ], ], '$this->primaryKey()->comment(\'test comment\')' => [ - SchemaInterface::TYPE_PK . " COMMENT 'test comment'", + PseudoType::PK . " COMMENT 'test comment'", [ 'mysql' => "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'test comment'", 'sqlsrv' => 'int IDENTITY PRIMARY KEY', ], ], '$this->json()' => [ - SchemaInterface::TYPE_JSON, + ColumnType::JSON, [ 'pgsql' => 'jsonb', ], diff --git a/tests/Provider/CommandProvider.php b/tests/Provider/CommandProvider.php index 0393f0e36..6c6dfc84a 100644 --- a/tests/Provider/CommandProvider.php +++ b/tests/Provider/CommandProvider.php @@ -9,6 +9,7 @@ use Traversable; use Yiisoft\Db\Command\DataType; use Yiisoft\Db\Command\Param; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Schema\SchemaInterface; @@ -921,7 +922,7 @@ public static function upsert(): array public static function columnTypes(): array { return [ - [SchemaInterface::TYPE_INTEGER], + [ColumnType::INTEGER], [new Column('string(100)')], ]; } diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 6529ad3f9..de73e3110 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -7,6 +7,7 @@ use ArrayIterator; use Yiisoft\Db\Command\DataType; use Yiisoft\Db\Command\Param; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Expression\JsonExpression; use Yiisoft\Db\Query\Query; @@ -1536,7 +1537,7 @@ public static function cteAliases(): array public static function columnTypes(): array { return [ - [SchemaInterface::TYPE_STRING], + [ColumnType::STRING], [new Column('string(100)')], ]; }