From f83eb22c6df43e087b026c20108632dc7a68f16f Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 6 Jan 2025 18:10:10 +0700 Subject: [PATCH 1/3] Remove `ColumnInterface` --- UPGRADE.md | 4 +- src/Command/AbstractCommand.php | 5 +- src/Command/CommandInterface.php | 11 +- src/Debug/CommandInterfaceProxy.php | 5 +- src/QueryBuilder/AbstractDDLQueryBuilder.php | 10 +- src/QueryBuilder/AbstractQueryBuilder.php | 39 +- src/QueryBuilder/DDLQueryBuilderInterface.php | 41 +- src/QueryBuilder/QueryBuilderInterface.php | 57 +- src/Schema/Builder/AbstractColumn.php | 398 --------- src/Schema/Builder/ColumnInterface.php | 144 ---- src/Schema/SchemaInterface.php | 8 - tests/AbstractQueryBuilderTest.php | 33 +- tests/AbstractSchemaTest.php | 9 - .../Common/CommonColumnSchemaBuilderTest.php | 93 --- tests/Common/CommonCommandTest.php | 48 ++ tests/Common/CommonQueryBuilderTest.php | 14 - tests/Db/Schema/ColumnSchemaBuilderTest.php | 280 ------- .../Provider/ColumnSchemaBuilderProvider.php | 29 - tests/Provider/ColumnTypes.php | 757 ------------------ tests/Provider/QueryBuilderProvider.php | 3 +- tests/Support/Stub/Column.php | 11 - tests/Support/Stub/Schema.php | 6 - 22 files changed, 95 insertions(+), 1910 deletions(-) delete mode 100644 src/Schema/Builder/AbstractColumn.php delete mode 100644 src/Schema/Builder/ColumnInterface.php delete mode 100644 tests/Common/CommonColumnSchemaBuilderTest.php delete mode 100644 tests/Db/Schema/ColumnSchemaBuilderTest.php delete mode 100644 tests/Provider/ColumnSchemaBuilderProvider.php delete mode 100644 tests/Provider/ColumnTypes.php delete mode 100644 tests/Support/Stub/Column.php diff --git a/UPGRADE.md b/UPGRADE.md index 019c57575..3dc3d1ef8 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -9,9 +9,9 @@ application when you upgrade the package from one version to another. ## Upgrade from 1.x to 2.x -### `ColumnInterface` as column type +### `ColumnSchemaInterface` as column type -Add `ColumnInterface` support and change type of parameter `$type` from `string` to `ColumnInterface|string` +Add `ColumnSchemaInterface` support and change type of parameter `$type` from `string` to `ColumnSchemaInterface|string` in `addColumn()` method of your classes that implement the following interfaces: - `Yiisoft\Db\Command\CommandInterface`; diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index 64100aa09..959f526f7 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -11,7 +11,6 @@ use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface; use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; -use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use function explode; @@ -132,7 +131,7 @@ public function addCheck(string $table, string $name, string $expression): stati return $this->setSql($sql)->requireTableSchemaRefresh($table); } - public function addColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): static + public function addColumn(string $table, string $column, ColumnSchemaInterface|string $type): static { $sql = $this->getQueryBuilder()->addColumn($table, $column, $type); return $this->setSql($sql)->requireTableSchemaRefresh($table); @@ -189,7 +188,7 @@ public function addUnique(string $table, string $name, array|string $columns): s return $this->setSql($sql)->requireTableSchemaRefresh($table); } - public function alterColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): static + public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): static { $sql = $this->getQueryBuilder()->alterColumn($table, $column, $type); return $this->setSql($sql)->requireTableSchemaRefresh($table); diff --git a/src/Command/CommandInterface.php b/src/Command/CommandInterface.php index 739388114..faf0530e4 100644 --- a/src/Command/CommandInterface.php +++ b/src/Command/CommandInterface.php @@ -18,7 +18,6 @@ use Yiisoft\Db\Query\Data\DataReaderInterface; use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface; -use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; /** @@ -47,13 +46,13 @@ public function addCheck(string $table, string $name, string $expression): stati * * @param string $table The name of the table to add new column to. * @param string $column The name of the new column. - * @param ColumnInterface|ColumnSchemaInterface|string $type The column type. + * @param ColumnSchemaInterface|string $type The column type. * {@see QueryBuilder::buildColumnDefinition()} will be called to convert the given column type to the database one. * For example, `string` will be converted to `varchar(255)`, and `string not null` becomes `varchar(255) not null`. * * Note: The method will quote the `table` and `column` parameters before using them in the generated SQL. */ - public function addColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): static; + public function addColumn(string $table, string $column, ColumnSchemaInterface|string $type): static; /** * Builds an SQL command for adding a comment to a column. @@ -147,13 +146,13 @@ public function addPrimaryKey(string $table, string $name, array|string $columns * * @param string $table The table whose column is to change. * @param string $column The name of the column to change. - * @param ColumnInterface|ColumnSchemaInterface|string $type The column type. + * @param ColumnSchemaInterface|string $type The column type. * {@see QueryBuilder::buildColumnDefinition()} will be called to convert the give column type to the physical one. * For example, `string` will be converted as `varchar(255)`, and `string not null` becomes `varchar(255) not null`. * * Note: The method will quote the `table` and `column` parameters before using them in the generated SQL. */ - public function alterColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): static; + public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): static; /** * Creates a batch INSERT command. @@ -326,7 +325,7 @@ public function createIndex( * into SQL representation. For example, it will convert `string not null` to `varchar(255) not null` * and `pk` to `int PRIMARY KEY AUTO_INCREMENT` (for MySQL). * - * The preferred method is to use {@see ColumnBuilder} to generate column definitions as instances of + * The preferred way is to use {@see ColumnBuilder} to generate column definitions as instances of * {@see ColumnSchemaInterface}. * * ```php diff --git a/src/Debug/CommandInterfaceProxy.php b/src/Debug/CommandInterfaceProxy.php index 338d49b2c..eceb0b796 100644 --- a/src/Debug/CommandInterfaceProxy.php +++ b/src/Debug/CommandInterfaceProxy.php @@ -9,7 +9,6 @@ use Yiisoft\Db\Command\CommandInterface; use Yiisoft\Db\Query\Data\DataReaderInterface; use Yiisoft\Db\Query\QueryInterface; -use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; final class CommandInterfaceProxy implements CommandInterface @@ -31,7 +30,7 @@ public function addCheck(string $table, string $name, string $expression): stati /** * @psalm-suppress MixedArgument */ - public function addColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): static + public function addColumn(string $table, string $column, ColumnSchemaInterface|string $type): static { return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector); } @@ -94,7 +93,7 @@ public function addUnique(string $table, string $name, array|string $columns): s /** * @psalm-suppress MixedArgument */ - public function alterColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): static + public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): static { return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector); } diff --git a/src/QueryBuilder/AbstractDDLQueryBuilder.php b/src/QueryBuilder/AbstractDDLQueryBuilder.php index de8c8e1b6..4afd7f830 100644 --- a/src/QueryBuilder/AbstractDDLQueryBuilder.php +++ b/src/QueryBuilder/AbstractDDLQueryBuilder.php @@ -6,7 +6,6 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Query\QueryInterface; -use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\QuoterInterface; use Yiisoft\Db\Schema\SchemaInterface; @@ -40,7 +39,7 @@ public function addCheck(string $table, string $name, string $expression): strin . ' CHECK (' . $this->quoter->quoteSql($expression) . ')'; } - public function addColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): string + public function addColumn(string $table, string $column, ColumnSchemaInterface|string $type): string { return 'ALTER TABLE ' . $this->quoter->quoteTableName($table) @@ -134,11 +133,8 @@ public function addUnique(string $table, string $name, array|string $columns): s . ' UNIQUE (' . implode(', ', $columns) . ')'; } - public function alterColumn( - string $table, - string $column, - ColumnInterface|ColumnSchemaInterface|string $type - ): string { + public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): string + { return 'ALTER TABLE ' . $this->quoter->quoteTableName($table) . ' CHANGE ' diff --git a/src/QueryBuilder/AbstractQueryBuilder.php b/src/QueryBuilder/AbstractQueryBuilder.php index 0b8a1d275..c91ed0c89 100644 --- a/src/QueryBuilder/AbstractQueryBuilder.php +++ b/src/QueryBuilder/AbstractQueryBuilder.php @@ -15,7 +15,6 @@ use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\QueryBuilder\Condition\Interface\ConditionInterface; -use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\QuoterInterface; use Yiisoft\Db\Schema\SchemaInterface; @@ -81,7 +80,7 @@ public function addCheck(string $table, string $name, string $expression): strin return $this->ddlBuilder->addCheck($table, $name, $expression); } - public function addColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): string + public function addColumn(string $table, string $column, ColumnSchemaInterface|string $type): string { return $this->ddlBuilder->addColumn($table, $column, $type); } @@ -131,7 +130,7 @@ public function addUnique(string $table, string $name, array|string $columns): s return $this->ddlBuilder->addUnique($table, $name, $columns); } - public function alterColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): string + public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): string { return $this->ddlBuilder->alterColumn($table, $column, $type); } @@ -175,12 +174,8 @@ public function build(QueryInterface $query, array $params = []): array return $this->dqlBuilder->build($query, $params); } - public function buildColumnDefinition(ColumnInterface|ColumnSchemaInterface|string $column): string + public function buildColumnDefinition(ColumnSchemaInterface|string $column): string { - if ($column instanceof ColumnInterface) { - $column = $column->asString(); - } - if (is_string($column)) { $column = $this->schema->getColumnFactory()->fromDefinition($column); } @@ -364,34 +359,6 @@ public function getColumnDefinitionBuilder(): ColumnDefinitionBuilderInterface return $this->columnDefinitionBuilder; } - /** @deprecated Use {@see buildColumnDefinition()}. Will be removed in version 2.0. */ - public function getColumnType(ColumnInterface|string $type): string - { - if ($type instanceof ColumnInterface) { - $type = $type->asString(); - } - - if (isset($this->typeMap[$type])) { - return $this->typeMap[$type]; - } - - if (preg_match('/^(\w+)\((.+?)\)(.*)$/', $type, $matches)) { - if (isset($this->typeMap[$matches[1]])) { - return preg_replace( - '/\(.+\)/', - '(' . $matches[2] . ')', - $this->typeMap[$matches[1]] - ) . $matches[3]; - } - } elseif (preg_match('/^(\w+)\s+/', $type, $matches)) { - if (isset($this->typeMap[$matches[1]])) { - return preg_replace('/^\w+/', $this->typeMap[$matches[1]], $type); - } - } - - return $type; - } - public function getExpressionBuilder(ExpressionInterface $expression): object { return $this->dqlBuilder->getExpressionBuilder($expression); diff --git a/src/QueryBuilder/DDLQueryBuilderInterface.php b/src/QueryBuilder/DDLQueryBuilderInterface.php index 28319048e..e3af883ed 100644 --- a/src/QueryBuilder/DDLQueryBuilderInterface.php +++ b/src/QueryBuilder/DDLQueryBuilderInterface.php @@ -9,7 +9,6 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Query\QueryInterface; -use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; /** @@ -37,17 +36,22 @@ public function addCheck(string $table, string $name, string $expression): strin * * @param string $table The table to add the new column will to. * @param string $column The name of the new column. - * @param ColumnInterface|ColumnSchemaInterface|string $type The column type. - * {@see getColumnType()} Method will be invoked to convert an abstract column type (if any) into the physical one. - * Anything that isn't recognized as an abstract type will be kept in the generated SQL. - * For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become - * 'varchar(255) not null'. + * @param ColumnSchemaInterface|string $type The column type which can contain a native database column type, + * {@see ColumnType abstract} or {@see PseudoType pseudo} type, or can be represented as instance of + * {@see ColumnSchemaInterface}. + * + * The {@see QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions + * into SQL representation. For example, it will convert `string not null` to `varchar(255) not null` + * and `pk` to `int PRIMARY KEY AUTO_INCREMENT` (for MySQL). + * + * The preferred way is to use {@see ColumnBuilder} to generate column definitions as instances of + * {@see ColumnSchemaInterface}. * * @return string The SQL statement for adding a new column. * * Note: The method will quote the `table` and `column` parameters before using them in the generated SQL. */ - public function addColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): string; + public function addColumn(string $table, string $column, ColumnSchemaInterface|string $type): string; /** * Builds an SQL command for adding comment to column. @@ -160,17 +164,22 @@ public function addUnique(string $table, string $name, array|string $columns): s * * @param string $table The table whose column is to change. * @param string $column The name of the column to change. - * @param ColumnInterface|ColumnSchemaInterface|string $type The new column type. - * {@see getColumnType()} Method will be invoked to convert an abstract column type (if any) into the physical one. - * Anything that isn't recognized as an abstract type will be kept in the generated SQL. - * For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become - * 'varchar(255) not null'. + * @param ColumnSchemaInterface|string $type The column type which can contain a native database column type, + * {@see ColumnType abstract} or {@see PseudoType pseudo} type, or can be represented as instance of + * {@see ColumnSchemaInterface}. + * + * The {@see QueryBuilderInterface::buildColumnDefinition()} method will be invoked to convert column definitions + * into SQL representation. For example, it will convert `string not null` to `varchar(255) not null` + * and `pk` to `int PRIMARY KEY AUTO_INCREMENT` (for MySQL). + * + * The preferred way is to use {@see ColumnBuilder} to generate column definitions as instances of + * {@see ColumnSchemaInterface}. * * @return string The SQL statement for changing the definition of a column. * * Note: The method will quote the `table` and `column` parameters before using them in the generated SQL. */ - public function alterColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): string; + public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): string; /** * Builds an SQL statement for enabling or disabling integrity check. @@ -226,7 +235,7 @@ public function createIndex( * into SQL representation. For example, it will convert `string not null` to `varchar(255) not null` * and `pk` to `int PRIMARY KEY AUTO_INCREMENT` (for MySQL). * - * The preferred method is to use {@see ColumnBuilder} to generate column definitions as instances of + * The preferred way is to use {@see ColumnBuilder} to generate column definitions as instances of * {@see ColumnSchemaInterface}. * * ```php @@ -250,14 +259,14 @@ public function createIndex( * * @param string $table The name of the table to create. * @param array $columns The columns (name => definition) in the new table. - * The definition can be `string` or {@see ColumnInterface} or {@see ColumnSchemaInterface} instance. + * The definition can be `string` or {@see ColumnSchemaInterface} instance. * @param string|null $options More SQL fragments to append to the generated SQL. * * @return string The SQL statement for creating a new DB table. * * Note: The method will quote the `table` and `columns` parameter before using it in the generated SQL. * - * @psalm-param array|string[] $columns + * @psalm-param array|string[] $columns */ public function createTable(string $table, array $columns, string $options = null): string; diff --git a/src/QueryBuilder/QueryBuilderInterface.php b/src/QueryBuilder/QueryBuilderInterface.php index 5f4cc834b..9de77b6ac 100644 --- a/src/QueryBuilder/QueryBuilderInterface.php +++ b/src/QueryBuilder/QueryBuilderInterface.php @@ -10,7 +10,6 @@ use Yiisoft\Db\Exception\InvalidArgumentException; use Yiisoft\Db\Expression\ExpressionBuilderInterface; use Yiisoft\Db\Expression\ExpressionInterface; -use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\QuoterInterface; @@ -42,62 +41,12 @@ public function bindParam(mixed $value, array &$params = []): string; /** * Builds column definition based on given column instance. * - * @param ColumnInterface|ColumnSchemaInterface|string $column the column instance or string column definition which - * should be converted into a database string representation. + * @param ColumnSchemaInterface|string $column the column instance or string column definition which should be + * converted into a database string representation. * * @return string the SQL column definition. */ - public function buildColumnDefinition(ColumnInterface|ColumnSchemaInterface|string $column): string; - - /** - * Converts an abstract column type into a physical column type. - * - * The conversion is done using the type map specified in {@see typeMap}. - * The following abstract column types are supported (using MySQL as an example to explain the corresponding - * physical types): - * - * - `pk`: an auto-incremental primary key type, will be converted into "int(11) NOT NULL AUTO_INCREMENT PRIMARY - * KEY" - * - `bigpk`: an auto incremental primary key type, will be converted into "bigint(20) NOT NULL AUTO_INCREMENT - * PRIMARY KEY" - * - `upk`: an unsigned auto incremental primary key type, will be converted into "int(10) UNSIGNED NOT NULL - * AUTO_INCREMENT PRIMARY KEY" - * - `char`: char type, will be converted into "char(1)" - * - `string`: string type, will be converted into "varchar(255)" - * - `text`: a long string type, will be converted into "text" - * - `smallint`: a small integer type, will be converted into "smallint(6)" - * - `integer`: integer type, will be converted into "int(11)" - * - `bigint`: a big integer type, will be converted into "bigint(20)" - * - `boolean`: boolean type, will be converted into "tinyint(1)" - * - `float``: float number type, will be converted into "float" - * - `decimal`: decimal number type, will be converted into "decimal" - * - `datetime`: datetime type, will be converted into "datetime" - * - `timestamp`: timestamp type, will be converted into "timestamp" - * - `time`: time type, will be converted into "time" - * - `date`: date type, will be converted into "date" - * - `money`: money type, will be converted into "decimal(19,4)" - * - `binary`: binary data type, will be converted into "blob" - * - * If the abstract type has two or more parts separated by spaces (such as "string NOT NULL"), then only the first - * part will be converted, and the rest of the parts will be appended to the converted result. - * - * For example, 'string NOT NULL' is converted to 'varchar(255) NOT NULL'. - * - * For some abstract types, you can also specify a length or precision constraint by appending it in round brackets - * directly to the type. - * - * For example, `string(32)` will be converted into "varchar(32)" on a MySQL database. - * If the underlying DBMS doesn't support these kinds of constraints for a type, it will be ignored. - * - * If a type can't be found in {@see typeMap}, it will be returned without any change. - * - * @param ColumnInterface|string $type Abstract column type. - * - * @return string Physical column type. - * - * @deprecated Use {@see buildColumnDefinition()}. Will be removed in version 2.0. - */ - public function getColumnType(ColumnInterface|string $type): string; + public function buildColumnDefinition(ColumnSchemaInterface|string $column): string; /** * Returns the column definition builder for the current DBMS. diff --git a/src/Schema/Builder/AbstractColumn.php b/src/Schema/Builder/AbstractColumn.php deleted file mode 100644 index 1ee38c722..000000000 --- a/src/Schema/Builder/AbstractColumn.php +++ /dev/null @@ -1,398 +0,0 @@ -notNull()->defaultValue(0); - * ``` - * - * Provides a fluent interface, which means that the methods can be chained together to create a column schema with - * many properties in a single line of code. - * - * @deprecated Use {@see AbstractColumnSchema} instead. Will be removed in 2.0.0. - */ -abstract class AbstractColumn implements ColumnInterface -{ - /** - * Allows you to group and define the abstract column type as primary key. - */ - public const TYPE_CATEGORY_PK = 'pk'; - /** - * Allows you to group and define the abstract column type as `string`. - */ - public const TYPE_CATEGORY_STRING = 'string'; - /** - * Allows you to group and define the abstract column type as `numeric`. - */ - public const TYPE_CATEGORY_NUMERIC = 'numeric'; - /** - * Allows you to group and define the abstract column type as `time`. - */ - public const TYPE_CATEGORY_TIME = 'time'; - /** - * Allows you to group and define the abstract column type as `other`. - */ - public const TYPE_CATEGORY_OTHER = 'other'; - /** - * Allows you to group and define the abstract column type as `uuid`. - */ - public const TYPE_CATEGORY_UUID = 'uuid'; - /** - * Allows you to group and define the abstract column type as `uuid` primary key. - */ - public const TYPE_CATEGORY_UUID_PK = 'uuid_pk'; - - protected bool|null $isNotNull = null; - protected bool $isUnique = false; - protected string|null $check = null; - protected mixed $default = null; - protected string|null $append = null; - protected bool $isUnsigned = false; - protected string|null $comment = null; - protected string $format = '{type}{length}{notnull}{unique}{default}{check}{comment}{append}'; - - /** @psalm-var string[] */ - private array $categoryMap = [ - 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, - ]; - - /** - * @psalm-param string[]|int[]|int|string|null $length - */ - public function __construct( - protected string $type, - protected int|string|array|null $length = null - ) { - } - - public function notNull(): static - { - $this->isNotNull = true; - return $this; - } - - public function null(): static - { - $this->isNotNull = false; - return $this; - } - - public function unique(): static - { - $this->isUnique = true; - return $this; - } - - public function check(string|null $sql): static - { - $this->check = $sql; - return $this; - } - - public function defaultValue(mixed $default): static - { - if ($default === null) { - $this->null(); - } - - $this->default = $default; - - return $this; - } - - public function comment(string|null $comment): static - { - $this->comment = $comment; - return $this; - } - - /** - * Marks column as unsigned. - */ - public function unsigned(): static - { - $this->type = match ($this->type) { - PseudoType::PK => PseudoType::UPK, - PseudoType::BIGPK => PseudoType::UBIGPK, - default => $this->type, - }; - - $this->isUnsigned = true; - - return $this; - } - - public function defaultExpression(string $sql): static - { - $this->default = new Expression($sql); - return $this; - } - - public function setFormat(string $format): void - { - $this->format = $format; - } - - public function append(string $sql): static - { - $this->append = $sql; - return $this; - } - - public function asString(): string - { - $format = match ($this->getTypeCategory()) { - self::TYPE_CATEGORY_PK => '{type}{check}{comment}{append}', - self::TYPE_CATEGORY_UUID => '{type}{notnull}{unique}{default}{check}{comment}{append}', - self::TYPE_CATEGORY_UUID_PK => '{type}{notnull}{default}{check}{comment}{append}', - default => $this->format, - }; - - return $this->buildCompleteString($format); - } - - public function getType(): string|null - { - return $this->type; - } - - public function getLength(): array|int|string|null - { - return $this->length; - } - - public function isNotNull(): bool|null - { - return $this->isNotNull; - } - - public function isUnique(): bool - { - return $this->isUnique; - } - - public function getCheck(): string|null - { - return $this->check; - } - - public function getDefault(): mixed - { - return $this->default; - } - - public function getAppend(): string|null - { - return $this->append; - } - - public function isUnsigned(): bool - { - return $this->isUnsigned; - } - - public function getCategoryMap(): array - { - return $this->categoryMap; - } - - public function getComment(): string|null - { - return $this->comment; - } - - /** - * Builds the length, precision part of the column. - * - * @return string A string containing the length/precision of the column. - */ - protected function buildLengthString(): string - { - if (empty($this->length)) { - return ''; - } - - if (is_array($this->length)) { - $this->length = implode(',', $this->length); - } - - return '(' . $this->length . ')'; - } - - /** - * Builds the not null constraint for the column. - * - * @return string A string 'NOT NULL' if {@see isNotNull} is true, 'NULL' if {@see isNotNull} is false or an empty - * string otherwise. - */ - protected function buildNotNullString(): string - { - if ($this->isNotNull === true) { - return ' NOT NULL'; - } - - if ($this->isNotNull === false) { - return ' NULL'; - } - - return ''; - } - - /** - * Builds the unique constraint for the column. - * - * @return string A string 'UNIQUE' if {@see isUnique} is true, otherwise it returns an empty string. - */ - protected function buildUniqueString(): string - { - return $this->isUnique ? ' UNIQUE' : ''; - } - - /** - * Return the default value for the column. - * - * @return string|null string with default value of column. - */ - protected function buildDefaultValue(): string|null - { - if ($this->default === null) { - return $this->isNotNull === false ? 'NULL' : null; - } - - return match (gettype($this->default)) { - 'object', 'integer' => (string) $this->default, - 'double' => DbStringHelper::normalizeFloat((string) $this->default), - 'boolean' => $this->default ? 'TRUE' : 'FALSE', - default => "'$this->default'", - }; - } - - /** - * Builds the default value specification for the column. - * - * @return string A string containing the DEFAULT keyword and the default value. - */ - protected function buildDefaultString(): string - { - $defaultValue = $this->buildDefaultValue(); - if ($defaultValue === null) { - return ''; - } - - return ' DEFAULT ' . $defaultValue; - } - - /** - * Builds the check constraint for the column. - * - * @return string A string containing the CHECK constraint. - */ - protected function buildCheckString(): string - { - return !empty($this->check) ? " CHECK ($this->check)" : ''; - } - - /** - * Builds the unsigned string for column. Defaults to unsupported. - * - * @return string A string containing the UNSIGNED keyword. - */ - protected function buildUnsignedString(): string - { - return ''; - } - - /** - * Builds the custom string that's appended to column definition. - * - * @return string A string containing the custom SQL fragment appended to column definition. - */ - protected function buildAppendString(): string - { - return !empty($this->append) ? ' ' . $this->append : ''; - } - - /** - * @return string|null A string containing the column type category name. - */ - protected function getTypeCategory(): string|null - { - return $this->categoryMap[$this->type] ?? null; - } - - /** - * Builds the comment specification for the column. - * - * @return string A string containing the COMMENT keyword and the comment itself. - */ - protected function buildCommentString(): string - { - return ''; - } - - /** - * Returns the complete column definition from input format. - * - * @param string $format The format of the definition. - * - * @return string A string containing the complete column definition. - */ - protected function buildCompleteString(string $format): string - { - $placeholderValues = [ - '{type}' => $this->type, - '{length}' => $this->buildLengthString(), - '{unsigned}' => $this->buildUnsignedString(), - '{notnull}' => $this->buildNotNullString(), - '{unique}' => $this->buildUniqueString(), - '{default}' => $this->buildDefaultString(), - '{check}' => $this->buildCheckString(), - '{comment}' => $this->buildCommentString(), - '{append}' => $this->buildAppendString(), - ]; - - return strtr($format, $placeholderValues); - } -} diff --git a/src/Schema/Builder/ColumnInterface.php b/src/Schema/Builder/ColumnInterface.php deleted file mode 100644 index 220c6bdb9..000000000 --- a/src/Schema/Builder/ColumnInterface.php +++ /dev/null @@ -1,144 +0,0 @@ -getConnection(); @@ -1835,36 +1834,6 @@ public function testDropView(): void ); } - public function testGetColumnType(): void - { - $db = $this->getConnection(); - - $qb = $db->getQueryBuilder(); - - $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)); - } - /** * @throws InvalidArgumentException */ diff --git a/tests/AbstractSchemaTest.php b/tests/AbstractSchemaTest.php index 19324ab55..4430c9cd4 100644 --- a/tests/AbstractSchemaTest.php +++ b/tests/AbstractSchemaTest.php @@ -6,7 +6,6 @@ use PHPUnit\Framework\TestCase; use Yiisoft\Db\Command\DataType; -use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Tests\Support\Assert; use Yiisoft\Db\Tests\Support\TestTrait; @@ -18,14 +17,6 @@ abstract class AbstractSchemaTest extends TestCase { use TestTrait; - public function testCreateColumnSchemaBuilder(): void - { - $columnSchemaBuilder = $this->getConnection()->getSchema()->createColumn('string'); - - $this->assertInstanceOf(ColumnInterface::class, $columnSchemaBuilder); - $this->assertSame('string', $columnSchemaBuilder->getType()); - } - public function testGetDefaultSchema(): void { $db = $this->getConnection(); diff --git a/tests/Common/CommonColumnSchemaBuilderTest.php b/tests/Common/CommonColumnSchemaBuilderTest.php deleted file mode 100644 index 9374651ba..000000000 --- a/tests/Common/CommonColumnSchemaBuilderTest.php +++ /dev/null @@ -1,93 +0,0 @@ -checkBuildString($expected, $type, $length, $calls); - } - - public function testUuid(): void - { - $db = $this->getConnection(); - $schema = $db->getSchema(); - - $tableName = '{{%column_schema_builder_types}}'; - if ($db->getTableSchema($tableName, true)) { - $db->createCommand()->dropTable($tableName)->execute(); - } - - $db->createCommand()->createTable($tableName, [ - 'uuid_pk' => $schema->createColumn(PseudoType::UUID_PK), - 'int_col' => $schema->createColumn(ColumnType::INTEGER), - ])->execute(); - $tableSchema = $db->getTableSchema($tableName, true); - $this->assertNotNull($tableSchema); - - $uuidValue = $uuidSource = '738146be-87b1-49f2-9913-36142fb6fcbe'; - - $uuidValue = match ($db->getDriverName()) { - 'oci' => new Expression("HEXTORAW(REPLACE(:uuid, '-', ''))", [':uuid' => $uuidValue]), - 'mysql' => new Expression("UNHEX(REPLACE(:uuid, '-', ''))", [':uuid' => $uuidValue]), - 'sqlite' => new Param(DbUuidHelper::uuidToBlob($uuidValue), DataType::LOB), - 'sqlsrv' => new Expression('CONVERT(uniqueidentifier, :uuid)', [':uuid' => $uuidValue]), - default => $uuidValue, - }; - - $db->createCommand()->insert($tableName, [ - 'int_col' => 1, - 'uuid_pk' => $uuidValue, - ])->execute(); - - $uuid = (new Query($db)) - ->select(['[[uuid_pk]]']) - ->from($tableName) - ->where(['int_col' => 1]) - ->scalar() - ; - - $uuidString = strtolower(DbUuidHelper::toUuid($uuid)); - - $this->assertEquals($uuidSource, $uuidString); - - $db->close(); - } - - protected function checkBuildString(string $expected, string $type, int|null $length, array $calls): void - { - $db = $this->getConnection(); - - $schema = $db->getSchema(); - $builder = $schema->createColumn($type, $length); - - foreach ($calls as $call) { - $method = array_shift($call); - ($builder->$method(...))(...$call); - } - - $this->assertSame($expected, $builder->asString()); - - $db->close(); - } -} diff --git a/tests/Common/CommonCommandTest.php b/tests/Common/CommonCommandTest.php index bb5947fed..988d64d16 100644 --- a/tests/Common/CommonCommandTest.php +++ b/tests/Common/CommonCommandTest.php @@ -6,6 +6,8 @@ use ReflectionException; 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\Driver\Pdo\AbstractPdoCommand; @@ -19,6 +21,7 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Expression\ExpressionInterface; +use Yiisoft\Db\Helper\DbUuidHelper; use Yiisoft\Db\Query\Data\DataReader; use Yiisoft\Db\Query\Data\DataReaderInterface; use Yiisoft\Db\Query\Query; @@ -2057,4 +2060,49 @@ public function testInsertWithReturningPksEmptyValuesAndNoPk() $this->assertSame([], $pkValues); } + + public function testUuid(): void + { + $db = $this->getConnection(); + $command = $db->createCommand(); + + $tableName = '{{%test_uuid}}'; + if ($db->getTableSchema($tableName, true)) { + $db->createCommand()->dropTable($tableName)->execute(); + } + + $command->createTable($tableName, [ + 'uuid_pk' => ColumnBuilder::uuidPrimaryKey(), + 'int_col' => ColumnBuilder::integer(), + ])->execute(); + $tableSchema = $db->getTableSchema($tableName, true); + $this->assertNotNull($tableSchema); + + $uuidValue = $uuidSource = '738146be-87b1-49f2-9913-36142fb6fcbe'; + + $uuidValue = match ($db->getDriverName()) { + 'oci' => new Expression("HEXTORAW(REPLACE(:uuid, '-', ''))", [':uuid' => $uuidValue]), + 'mysql' => new Expression("UNHEX(REPLACE(:uuid, '-', ''))", [':uuid' => $uuidValue]), + 'sqlite' => new Param(DbUuidHelper::uuidToBlob($uuidValue), DataType::LOB), + 'sqlsrv' => new Expression('CONVERT(uniqueidentifier, :uuid)', [':uuid' => $uuidValue]), + default => $uuidValue, + }; + + $command->insert($tableName, [ + 'int_col' => 1, + 'uuid_pk' => $uuidValue, + ])->execute(); + + $uuid = (new Query($db)) + ->select(['[[uuid_pk]]']) + ->from($tableName) + ->where(['int_col' => 1]) + ->scalar(); + + $uuidString = strtolower(DbUuidHelper::toUuid($uuid)); + + $this->assertSame($uuidSource, $uuidString); + + $db->close(); + } } diff --git a/tests/Common/CommonQueryBuilderTest.php b/tests/Common/CommonQueryBuilderTest.php index 68f87042d..1d00d94a4 100644 --- a/tests/Common/CommonQueryBuilderTest.php +++ b/tests/Common/CommonQueryBuilderTest.php @@ -9,7 +9,6 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Tests\AbstractQueryBuilderTest; -use Yiisoft\Db\Tests\Provider\ColumnTypes; use Yiisoft\Db\Tests\Provider\QueryBuilderProvider; abstract class CommonQueryBuilderTest extends AbstractQueryBuilderTest @@ -19,19 +18,6 @@ public function getBuildColumnDefinitionProvider(): array return QueryBuilderProvider::buildColumnDefinition(); } - public function testGetColumnType(): void - { - $db = $this->getConnection(); - $qb = $db->getQueryBuilder(); - $columnTypes = (new ColumnTypes($db))->getColumnTypes(); - - foreach ($columnTypes as [$column, $expected]) { - $this->assertEquals($expected, $qb->getColumnType($column)); - } - - $db->close(); - } - #[DoesNotPerformAssertions] public function testCreateTableWithBuildColumnDefinition(): void { diff --git a/tests/Db/Schema/ColumnSchemaBuilderTest.php b/tests/Db/Schema/ColumnSchemaBuilderTest.php deleted file mode 100644 index 7c3fc7c32..000000000 --- a/tests/Db/Schema/ColumnSchemaBuilderTest.php +++ /dev/null @@ -1,280 +0,0 @@ -assertSame('string', $column->asString()); - $this->assertSame('string bar', $column->append('bar')->asString()); - $this->assertSame('string foo', $column->append('foo')->asString()); - } - - public function testAppendWithEmptyString(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string', $column->append('')->asString()); - } - - public function testCheck(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string CHECK (value > 5)', $column->check('value > 5')->asString()); - } - - public function testCheckWithEmptyString(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string', $column->check('')->asString()); - } - - public function testCheckWithNull(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string', $column->check(null)->asString()); - } - - public function testComment(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string', $column->comment('comment')->asString()); - } - - public function testCommentWithEmptyString(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string', $column->comment('')->asString()); - } - - public function testCommentWithNull(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string', $column->comment(null)->asString()); - } - - public function testDefaultExpression(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame("string DEFAULT 'expression'", $column->defaultExpression("'expression'")->asString()); - } - - public function testDefaultExpressionWithEmptyString(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string DEFAULT ', $column->defaultExpression('')->asString()); - } - - public function testDefaultValue(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame("string DEFAULT ''value''", $column->defaultValue("'value'")->asString()); - } - - public function testDefaultValueWithEmptyString(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame("string DEFAULT ''", $column->defaultValue('')->asString()); - } - - public function testDefaultValueWithNull(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string NULL DEFAULT NULL', $column->defaultValue(null)->asString()); - } - - public function testGetAppend(): void - { - $column = new Column('string'); - - $this->assertNull($column->getAppend()); - $this->assertSame('bar', $column->append('bar')->getAppend()); - $this->assertSame('bar', $column->getAppend()); - } - - public function testGetCategoryMap(): void - { - $column = new Column('string'); - - $this->assertSame( - [ - 'pk' => 'pk', - 'upk' => 'pk', - 'bigpk' => 'pk', - 'ubigpk' => 'pk', - 'char' => 'string', - 'string' => 'string', - 'text' => 'string', - 'tinyint' => 'numeric', - 'smallint' => 'numeric', - 'integer' => 'numeric', - 'bigint' => 'numeric', - 'float' => 'numeric', - 'double' => 'numeric', - 'decimal' => 'numeric', - 'datetime' => 'time', - 'timestamp' => 'time', - 'time' => 'time', - 'date' => 'time', - 'binary' => 'other', - 'boolean' => 'numeric', - 'money' => 'numeric', - 'uuid' => 'uuid', - 'uuid_pk' => 'uuid_pk', - ], - $column->getCategoryMap(), - ); - } - - public function testGetCheck(): void - { - $column = new Column('string'); - - $this->assertNull($column->getCheck()); - $this->assertSame('value > 5', $column->check('value > 5')->getCheck()); - $this->assertSame('value > 5', $column->getCheck()); - } - - public function testGetComment(): void - { - $column = new Column('string'); - - $this->assertNull($column->getComment()); - $this->assertSame('comment', $column->comment('comment')->getComment()); - $this->assertSame('comment', $column->getComment()); - } - - public function testGetDefault(): void - { - $column = new Column('string'); - - $this->assertNull($column->getDefault()); - $this->assertSame("'value'", $column->defaultValue("'value'")->getDefault()); - $this->assertSame("'value'", $column->getDefault()); - } - - public function testGetDefaultExpression(): void - { - $column = new Column('string'); - - $this->assertNull($column->getDefault()); - $this->assertInstanceOf(Expression::class, $column->defaultExpression("'expression'")->getDefault()); - $this->assertInstanceOf(Expression::class, $column->getDefault()); - } - - public function testGetLength(): void - { - $column = new Column('string', 10); - - $this->assertSame(10, $column->getLength()); - } - - public function testIsNotNull(): void - { - $column = new Column('string'); - - $this->assertNull($column->isNotNull()); - $this->assertTrue($column->notNull()->isNotNull()); - } - - public function testIsUnique(): void - { - $column = new Column('string'); - - $this->assertFalse($column->isUnique()); - $this->assertTrue($column->unique()->isUnique()); - } - - public function testIsUnsigned(): void - { - $column = new Column('pk'); - - $this->assertFalse($column->isUnsigned()); - $this->assertTrue($column->unsigned()->isUnsigned()); - } - - public function testLengthWithArray(): void - { - $column = new Column('integer', [10, 2]); - - $this->assertSame('integer(10,2)', $column->asString()); - } - - public function testNotnull(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string NOT NULL', $column->notNull()->asString()); - } - - public function testNull(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string NULL DEFAULT NULL', $column->null()->asString()); - } - - public function testUnique(): void - { - $column = new Column('string'); - - $this->assertSame('string', $column->asString()); - $this->assertSame('string UNIQUE', $column->unique()->asString()); - } - - public function testUnsignedTypePk(): void - { - $column = new Column(PseudoType::PK); - - $this->assertSame('pk', $column->asString()); - $this->assertSame('upk', $column->unsigned()->asString()); - } - - public function testUnsignedTypeUbigPk(): void - { - $column = new Column(PseudoType::BIGPK); - - $this->assertSame('bigpk', $column->asString()); - $this->assertSame('ubigpk', $column->unsigned()->asString()); - } -} diff --git a/tests/Provider/ColumnSchemaBuilderProvider.php b/tests/Provider/ColumnSchemaBuilderProvider.php deleted file mode 100644 index 86303b61f..000000000 --- a/tests/Provider/ColumnSchemaBuilderProvider.php +++ /dev/null @@ -1,29 +0,0 @@ -bigInteger()' => [ - ColumnType::BIGINT, - [ - 'mysql' => 'bigint(20)', - 'pgsql' => 'bigint', - 'sqlite' => 'bigint', - 'oci' => 'NUMBER(20)', - 'sqlsrv' => 'bigint', - ], - ], - '$this->bigInteger()->notNull()' => [ - ColumnType::BIGINT . ' NOT NULL', - [ - 'mysql' => 'bigint(20) NOT NULL', - 'pgsql' => 'bigint NOT NULL', - 'sqlite' => 'bigint NOT NULL', - 'oci' => 'NUMBER(20) NOT NULL', - 'sqlsrv' => 'bigint NOT NULL', - ], - ], - '$this->bigInteger()->check(\'value > 5\')' => [ - ColumnType::BIGINT . ' CHECK (value > 5)', - [ - 'mysql' => 'bigint(20) CHECK (value > 5)', - 'pgsql' => 'bigint CHECK (value > 5)', - 'sqlite' => 'bigint CHECK (value > 5)', - 'oci' => 'NUMBER(20) CHECK (value > 5)', - 'sqlsrv' => 'bigint CHECK (value > 5)', - ], - ], - '$this->bigInteger(8)' => [ - ColumnType::BIGINT . '(8)', - [ - 'mysql' => 'bigint(8)', - 'pgsql' => 'bigint', - 'sqlite' => 'bigint', - 'oci' => 'NUMBER(8)', - 'sqlsrv' => 'bigint', - ], - ], - '$this->bigInteger(8)->check(\'value > 5\')' => [ - ColumnType::BIGINT . '(8) CHECK (value > 5)', - [ - 'mysql' => 'bigint(8) CHECK (value > 5)', - 'pgsql' => 'bigint CHECK (value > 5)', - 'sqlite' => 'bigint CHECK (value > 5)', - 'oci' => 'NUMBER(8) CHECK (value > 5)', - 'sqlsrv' => 'bigint CHECK (value > 5)', - ], - ], - '$this->bigPrimaryKey()' => [ - PseudoType::BIGPK, - [ - 'mysql' => 'bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY', - 'pgsql' => 'bigserial NOT NULL PRIMARY KEY', - 'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', - ], - ], - '$this->binary()' => [ - ColumnType::BINARY, - [ - 'mysql' => 'blob', - 'pgsql' => 'bytea', - 'sqlite' => 'blob', - 'oci' => 'BLOB', - 'sqlsrv' => 'varbinary(max)', - ], - ], - '$this->boolean()->notNull()->defaultValue(1)' => [ - ColumnType::BOOLEAN . ' NOT NULL DEFAULT 1', - [ - 'mysql' => 'bit(1) NOT NULL DEFAULT 1', - 'sqlite' => 'boolean NOT NULL DEFAULT 1', - 'sqlsrv' => 'bit NOT NULL DEFAULT 1', - ], - ], - '$this->boolean()->notNull()->defaultValue(true)' => [ - ColumnType::BOOLEAN . ' NOT NULL DEFAULT TRUE', - [ - 'pgsql' => 'boolean NOT NULL DEFAULT TRUE', - ], - ], - '$this->boolean()' => [ - ColumnType::BOOLEAN, - [ - 'mysql' => 'bit(1)', - 'pgsql' => 'boolean', - 'sqlite' => 'boolean', - 'oci' => 'NUMBER(1)', - 'sqlsrv' => 'bit', - ], - ], - '$this->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%"\')' => [ - ColumnType::CHAR . ' CHECK (value LIKE "test%")', - [ - 'sqlite' => 'char(1) CHECK (value LIKE "test%")', - ], - ], - '$this->char()->notNull()' => [ - ColumnType::CHAR . ' NOT NULL', - [ - 'mysql' => 'char(1) NOT NULL', - 'pgsql' => 'char(1) NOT NULL', - 'sqlite' => 'char(1) NOT NULL', - 'oci' => 'CHAR(1) NOT NULL', - ], - ], - '$this->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%\\\'\')' => [ - ColumnType::CHAR . '(6) CHECK (value LIKE \'test%\')', - [ - 'mysql' => 'char(6) CHECK (value LIKE \'test%\')', - ], - ], - '$this->char(6)->unsigned()' => [ - ColumnType::CHAR . '(6)', - [ - 'pgsql' => 'char(6)', - ], - ], - '$this->char(6)' => [ - ColumnType::CHAR . '(6)', - [ - 'mysql' => 'char(6)', - 'pgsql' => 'char(6)', - 'sqlite' => 'char(6)', - 'oci' => 'CHAR(6)', - ], - ], - '$this->char()' => [ - ColumnType::CHAR, - [ - 'mysql' => 'char(1)', - 'pgsql' => 'char(1)', - 'sqlite' => 'char(1)', - 'oci' => 'CHAR(1)', - ], - ], - '$this->date()->notNull()' => [ - ColumnType::DATE . ' NOT NULL', - [ - 'pgsql' => 'date NOT NULL', - 'sqlite' => 'date NOT NULL', - 'oci' => 'DATE NOT NULL', - 'sqlsrv' => 'date NOT NULL', - ], - ], - '$this->date()' => [ - ColumnType::DATE, - [ - 'mysql' => 'date', - 'pgsql' => 'date', - 'sqlite' => 'date', - 'oci' => 'DATE', - 'sqlsrv' => 'date', - ], - ], - '$this->dateTime()->notNull()' => [ - ColumnType::DATETIME . ' NOT NULL', - [ - 'mysql' => 'datetime(0) NOT NULL', - 'pgsql' => 'timestamp(0) NOT NULL', - 'sqlite' => 'datetime NOT NULL', - 'oci' => 'TIMESTAMP(0) NOT NULL', - 'sqlsrv' => 'datetime NOT NULL', - ], - ], - '$this->dateTime()' => [ - ColumnType::DATETIME, - [ - 'mysql' => 'datetime(0)', - 'pgsql' => 'timestamp(0)', - 'sqlite' => 'datetime', - 'oci' => 'TIMESTAMP(0)', - 'sqlsrv' => 'datetime', - ], - ], - '$this->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)', - 'sqlite' => 'decimal(10,0) CHECK (value > 5.6)', - 'oci' => 'NUMBER(10,0) CHECK (value > 5.6)', - 'sqlsrv' => 'decimal(18,0) CHECK (value > 5.6)', - ], - ], - '$this->decimal()->notNull()' => [ - ColumnType::DECIMAL . ' NOT NULL', - [ - 'mysql' => 'decimal(10,0) NOT NULL', - 'pgsql' => 'numeric(10,0) NOT NULL', - 'sqlite' => 'decimal(10,0) NOT NULL', - 'oci' => 'NUMBER(10,0) NOT NULL', - 'sqlsrv' => 'decimal(18,0) NOT NULL', - ], - ], - '$this->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)', - 'sqlite' => 'decimal(12,4) CHECK (value > 5.6)', - 'oci' => 'NUMBER(12,4) CHECK (value > 5.6)', - 'sqlsrv' => 'decimal(12,4) CHECK (value > 5.6)', - ], - ], - '$this->decimal(12, 4)' => [ - ColumnType::DECIMAL . '(12,4)', - [ - 'mysql' => 'decimal(12,4)', - 'pgsql' => 'numeric(12,4)', - 'sqlite' => 'decimal(12,4)', - 'oci' => 'NUMBER(12,4)', - 'sqlsrv' => 'decimal(12,4)', - ], - ], - '$this->decimal()' => [ - ColumnType::DECIMAL, - [ - 'mysql' => 'decimal(10,0)', - 'pgsql' => 'numeric(10,0)', - 'sqlite' => 'decimal(10,0)', - 'oci' => 'NUMBER(10,0)', - 'sqlsrv' => 'decimal(18,0)', - ], - ], - '$this->double()->check(\'value > 5.6\')' => [ - ColumnType::DOUBLE . ' CHECK (value > 5.6)', - [ - 'mysql' => 'double CHECK (value > 5.6)', - 'pgsql' => 'double precision CHECK (value > 5.6)', - 'sqlite' => 'double CHECK (value > 5.6)', - 'oci' => 'BINARY_DOUBLE CHECK (value > 5.6)', - 'sqlsrv' => 'float CHECK (value > 5.6)', - ], - ], - '$this->double()->notNull()' => [ - ColumnType::DOUBLE . ' NOT NULL', - [ - 'mysql' => 'double NOT NULL', - 'pgsql' => 'double precision NOT NULL', - 'sqlite' => 'double NOT NULL', - 'oci' => 'BINARY_DOUBLE NOT NULL', - 'sqlsrv' => 'float NOT NULL', - ], - ], - '$this->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)', - 'sqlite' => 'double CHECK (value > 5.6)', - 'oci' => 'BINARY_DOUBLE CHECK (value > 5.6)', - 'sqlsrv' => 'float CHECK (value > 5.6)', - ], - ], - '$this->double(16)' => [ - ColumnType::DOUBLE . '(16)', - [ - 'mysql' => 'double', - 'sqlite' => 'double', - 'oci' => 'BINARY_DOUBLE', - 'sqlsrv' => 'float', - ], - ], - '$this->double()' => [ - ColumnType::DOUBLE, - [ - 'mysql' => 'double', - 'pgsql' => 'double precision', - 'sqlite' => 'double', - 'oci' => 'BINARY_DOUBLE', - 'sqlsrv' => 'float', - ], - ], - '$this->float()->check(\'value > 5.6\')' => [ - ColumnType::FLOAT . ' CHECK (value > 5.6)', - [ - 'mysql' => 'float CHECK (value > 5.6)', - 'pgsql' => 'double precision CHECK (value > 5.6)', - 'sqlite' => 'float CHECK (value > 5.6)', - 'oci' => 'BINARY_FLOAT CHECK (value > 5.6)', - 'sqlsrv' => 'float CHECK (value > 5.6)', - ], - ], - '$this->float()->notNull()' => [ - ColumnType::FLOAT . ' NOT NULL', - [ - 'mysql' => 'float NOT NULL', - 'pgsql' => 'double precision NOT NULL', - 'sqlite' => 'float NOT NULL', - 'oci' => 'BINARY_FLOAT NOT NULL', - 'sqlsrv' => 'float NOT NULL', - ], - ], - '$this->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)', - 'sqlite' => 'float CHECK (value > 5.6)', - 'oci' => 'BINARY_FLOAT CHECK (value > 5.6)', - 'sqlsrv' => 'float CHECK (value > 5.6)', - ], - ], - '$this->float(16)' => [ - ColumnType::FLOAT . '(16)', - [ - 'mysql' => 'float', - 'sqlite' => 'float', - 'oci' => 'BINARY_FLOAT', - 'sqlsrv' => 'float', - ], - ], - '$this->float()' => [ - ColumnType::FLOAT, - [ - 'mysql' => 'float', - 'pgsql' => 'double precision', - 'sqlite' => 'float', - 'oci' => 'BINARY_FLOAT', - 'sqlsrv' => 'float', - ], - ], - '$this->integer()->check(\'value > 5\')' => [ - ColumnType::INTEGER . ' CHECK (value > 5)', - [ - 'mysql' => 'int(11) CHECK (value > 5)', - 'pgsql' => 'integer CHECK (value > 5)', - 'sqlite' => 'integer CHECK (value > 5)', - 'oci' => 'NUMBER(10) CHECK (value > 5)', - 'sqlsrv' => 'int CHECK (value > 5)', - ], - ], - '$this->integer()->notNull()' => [ - ColumnType::INTEGER . ' NOT NULL', - [ - 'mysql' => 'int(11) NOT NULL', - 'pgsql' => 'integer NOT NULL', - 'sqlite' => 'integer NOT NULL', - 'oci' => 'NUMBER(10) NOT NULL', - 'sqlsrv' => 'int NOT NULL', - ], - ], - '$this->integer(8)->check(\'value > 5\')' => [ - ColumnType::INTEGER . '(8) CHECK (value > 5)', - [ - 'mysql' => 'int(8) CHECK (value > 5)', - 'pgsql' => 'integer CHECK (value > 5)', - 'sqlite' => 'integer CHECK (value > 5)', - 'oci' => 'NUMBER(8) CHECK (value > 5)', - 'sqlsrv' => 'int CHECK (value > 5)', - ], - ], - '$this->integer(8)->unsigned()' => [ - ColumnType::INTEGER . '(8)', - [ - 'pgsql' => 'integer', - ], - ], - '$this->integer(8)' => [ - ColumnType::INTEGER . '(8)', - [ - 'mysql' => 'int(8)', - 'pgsql' => 'integer', - 'sqlite' => 'integer', - 'oci' => 'NUMBER(8)', - 'sqlsrv' => 'int', - ], - ], - '$this->integer()' => [ - ColumnType::INTEGER, - [ - 'mysql' => 'int(11)', - 'pgsql' => 'integer', - 'sqlite' => 'integer', - 'oci' => 'NUMBER(10)', - 'sqlsrv' => 'int', - ], - ], - '$this->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)', - 'sqlite' => 'decimal(19,4) CHECK (value > 0.0)', - 'oci' => 'NUMBER(19,4) CHECK (value > 0.0)', - 'sqlsrv' => 'decimal(19,4) CHECK (value > 0.0)', - ], - ], - '$this->money()->notNull()' => [ - ColumnType::MONEY . ' NOT NULL', - [ - 'mysql' => 'decimal(19,4) NOT NULL', - 'pgsql' => 'numeric(19,4) NOT NULL', - 'sqlite' => 'decimal(19,4) NOT NULL', - 'oci' => 'NUMBER(19,4) NOT NULL', - 'sqlsrv' => 'decimal(19,4) NOT NULL', - ], - ], - '$this->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)', - 'sqlite' => 'decimal(16,2) CHECK (value > 0.0)', - 'oci' => 'NUMBER(16,2) CHECK (value > 0.0)', - 'sqlsrv' => 'decimal(16,2) CHECK (value > 0.0)', - ], - ], - '$this->money(16, 2)' => [ - ColumnType::MONEY . '(16,2)', - [ - 'mysql' => 'decimal(16,2)', - 'pgsql' => 'numeric(16,2)', - 'sqlite' => 'decimal(16,2)', - 'oci' => 'NUMBER(16,2)', - 'sqlsrv' => 'decimal(16,2)', - ], - ], - '$this->money()' => [ - ColumnType::MONEY, - [ - 'mysql' => 'decimal(19,4)', - 'pgsql' => 'numeric(19,4)', - 'sqlite' => 'decimal(19,4)', - 'oci' => 'NUMBER(19,4)', - 'sqlsrv' => 'decimal(19,4)', - ], - ], - '$this->primaryKey()->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)', - 'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL CHECK (value > 5)', - 'oci' => 'NUMBER(10) GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY CHECK (value > 5)', - 'sqlsrv' => 'int IDENTITY PRIMARY KEY CHECK (value > 5)', - ], - ], - '$this->primaryKey(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)' => [ - 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()' => [ - PseudoType::PK, - [ - 'mysql' => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY', - 'pgsql' => 'serial NOT NULL PRIMARY KEY', - 'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', - 'oci' => 'NUMBER(10) GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY', - 'sqlsrv' => 'int IDENTITY PRIMARY KEY', - ], - ], - '$this->tinyInteger(2)' => [ - ColumnType::TINYINT . '(2)', - [ - 'mysql' => 'tinyint(2)', - 'pgsql' => 'smallint', - 'sqlite' => 'tinyint', - 'oci' => 'NUMBER(2)', - 'sqlsrv' => 'tinyint', - ], - ], - '$this->tinyInteger()->unsigned()' => [ - ColumnType::TINYINT . ' UNSIGNED', - [ - 'mysql' => 'tinyint(3) UNSIGNED', - 'sqlite' => 'tinyint UNSIGNED', - ], - ], - '$this->tinyInteger()' => [ - ColumnType::TINYINT, - [ - 'mysql' => 'tinyint(3)', - 'pgsql' => 'smallint', - 'sqlite' => 'tinyint', - 'oci' => 'NUMBER(3)', - 'sqlsrv' => 'tinyint', - ], - ], - '$this->smallInteger(8)' => [ - ColumnType::SMALLINT . '(8)', - [ - 'mysql' => 'smallint(8)', - 'pgsql' => 'smallint', - 'sqlite' => 'smallint', - 'oci' => 'NUMBER(8)', - 'sqlsrv' => 'smallint', - ], - ], - '$this->smallInteger()' => [ - ColumnType::SMALLINT, - [ - 'mysql' => 'smallint(6)', - 'pgsql' => 'smallint', - 'sqlite' => 'smallint', - 'oci' => 'NUMBER(5)', - 'sqlsrv' => 'smallint', - ], - ], - '$this->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%')", - 'sqlsrv' => "nvarchar(255) CHECK (value LIKE 'test%')", - ], - ], - '$this->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()' => [ - ColumnType::STRING . ' NOT NULL', - [ - 'mysql' => 'varchar(255) NOT NULL', - 'pgsql' => 'varchar(255) NOT NULL', - 'sqlite' => 'varchar(255) NOT NULL', - 'oci' => 'VARCHAR2(255) NOT NULL', - 'sqlsrv' => 'nvarchar(255) NOT NULL', - ], - ], - '$this->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%')", - 'sqlsrv' => "nvarchar(32) CHECK (value LIKE 'test%')", - ], - ], - '$this->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)' => [ - ColumnType::STRING . '(32)', - [ - 'mysql' => 'varchar(32)', - 'pgsql' => 'varchar(32)', - 'sqlite' => 'varchar(32)', - 'oci' => 'VARCHAR2(32)', - 'sqlsrv' => 'nvarchar(32)', - ], - ], - '$this->string()' => [ - ColumnType::STRING, - [ - 'mysql' => 'varchar(255)', - 'pgsql' => 'varchar(255)', - 'sqlite' => 'varchar(255)', - 'oci' => 'VARCHAR2(255)', - 'sqlsrv' => 'nvarchar(255)', - ], - ], - '$this->text()->check("value LIKE \'test%\'")' => [ - ColumnType::TEXT . " CHECK (value LIKE 'test%')", - [ - 'mysql' => "text CHECK (value LIKE 'test%')", - 'sqlite' => "text CHECK (value LIKE 'test%')", - 'sqlsrv' => "nvarchar(max) CHECK (value LIKE 'test%')", - ], - ], - '$this->text()->notNull()' => [ - ColumnType::TEXT . ' NOT NULL', - [ - 'mysql' => 'text NOT NULL', - 'pgsql' => 'text NOT NULL', - 'sqlite' => 'text NOT NULL', - 'oci' => 'CLOB NOT NULL', - 'sqlsrv' => 'nvarchar(max) NOT NULL', - ], - ], - '$this->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()' => [ - ColumnType::TEXT, - [ - 'mysql' => 'text', - 'pgsql' => 'text', - 'sqlite' => 'text', - 'oci' => 'CLOB', - 'sqlsrv' => 'nvarchar(max)', - ], - ], - '$this->time()->notNull()' => [ - ColumnType::TIME . ' NOT NULL', - [ - 'mysql' => 'time(0) NOT NULL', - 'pgsql' => 'time(0) NOT NULL', - 'sqlite' => 'time NOT NULL', - 'oci' => 'INTERVAL DAY(0) TO SECOND(0) NOT NULL', - 'sqlsrv' => 'time NOT NULL', - ], - ], - '$this->time()' => [ - ColumnType::TIME, - [ - 'mysql' => 'time(0)', - 'pgsql' => 'time(0)', - 'sqlite' => 'time', - 'oci' => 'INTERVAL DAY(0) TO SECOND(0)', - 'sqlsrv' => 'time', - ], - ], - '$this->timestamp()->notNull()' => [ - ColumnType::TIMESTAMP . ' NOT NULL', - [ - 'mysql' => 'timestamp(0) NOT NULL', - 'pgsql' => 'timestamp(0) NOT NULL', - 'sqlite' => 'timestamp NOT NULL', - 'oci' => 'TIMESTAMP(0) NOT NULL', - 'sqlsrv' => 'datetime NOT NULL', - ], - ], - '$this->timestamp()->defaultValue(null)' => [ - ColumnType::TIMESTAMP . ' NULL DEFAULT NULL', - [ - 'mysql' => 'timestamp(0) NULL DEFAULT NULL', - 'pgsql' => 'timestamp(0) NULL DEFAULT NULL', - 'sqlite' => 'timestamp NULL DEFAULT NULL', - 'sqlsrv' => 'datetime NULL DEFAULT NULL', - ], - ], - '$this->timestamp(4)' => [ - ColumnType::TIMESTAMP . '(4)', - [ - 'pgsql' => 'timestamp(4)', - 'oci' => 'TIMESTAMP(4)', - ], - ], - '$this->timestamp()' => [ - ColumnType::TIMESTAMP, - [ - /** - * MySQL has its own TIMESTAMP test realization. - * - * {@see QueryBuilderTest::columnTypes()} - */ - 'pgsql' => 'timestamp(0)', - 'sqlite' => 'timestamp', - 'oci' => 'TIMESTAMP(0)', - 'sqlsrv' => 'datetime', - ], - ], - '$this->primaryKey()->unsigned()' => [ - PseudoType::UPK, - [ - 'mysql' => 'int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', - 'pgsql' => 'serial NOT NULL PRIMARY KEY', - 'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', - ], - ], - '$this->bigPrimaryKey()->unsigned()' => [ - PseudoType::UBIGPK, - [ - 'mysql' => 'bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', - 'pgsql' => 'bigserial NOT NULL PRIMARY KEY', - 'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', - ], - ], - '$this->integer()->comment(\'test comment\')' => [ - ColumnType::INTEGER . " COMMENT 'test comment'", - [ - 'mysql' => "int(11) COMMENT 'test comment'", - 'sqlsrv' => 'int', - ], - ], - '$this->primaryKey()->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()' => [ - ColumnType::JSON, - [ - 'pgsql' => 'jsonb', - ], - ], - ]; - - $driverName = $this->db->getDriverName(); - - foreach ($items as $i => $item) { - if (array_key_exists($driverName, $item[1])) { - $item[1] = $item[1][$driverName]; - $items[$i] = $item; - } else { - unset($items[$i]); - } - } - - return array_values($items); - } -} diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 0b1c55e05..78726f552 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -21,7 +21,6 @@ use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Tests\Support\DbHelper; use Yiisoft\Db\Tests\Support\Stringable; -use Yiisoft\Db\Tests\Support\Stub\Column; use Yiisoft\Db\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Support\TraversableObject; @@ -1551,7 +1550,7 @@ public static function columnTypes(): array { return [ [ColumnType::STRING], - [new Column('string(100)')], + [ColumnBuilder::string(100)], ]; } diff --git a/tests/Support/Stub/Column.php b/tests/Support/Stub/Column.php deleted file mode 100644 index f8b2f0dfe..000000000 --- a/tests/Support/Stub/Column.php +++ /dev/null @@ -1,11 +0,0 @@ - Date: Tue, 7 Jan 2025 03:32:57 +0000 Subject: [PATCH 2/3] Apply fixes from StyleCI --- src/QueryBuilder/AbstractQueryBuilder.php | 2 -- tests/AbstractQueryBuilderTest.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/QueryBuilder/AbstractQueryBuilder.php b/src/QueryBuilder/AbstractQueryBuilder.php index c91ed0c89..440b0d068 100644 --- a/src/QueryBuilder/AbstractQueryBuilder.php +++ b/src/QueryBuilder/AbstractQueryBuilder.php @@ -24,8 +24,6 @@ use function get_resource_type; use function gettype; use function is_string; -use function preg_match; -use function preg_replace; use function stream_get_contents; /** diff --git a/tests/AbstractQueryBuilderTest.php b/tests/AbstractQueryBuilderTest.php index 75ea48b07..dd6004d24 100644 --- a/tests/AbstractQueryBuilderTest.php +++ b/tests/AbstractQueryBuilderTest.php @@ -12,8 +12,6 @@ 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; From 29a88a82b5cbf3ead61a753f8daebcb928095478 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 7 Jan 2025 11:16:43 +0700 Subject: [PATCH 3/3] Add lines to CHANGELOG.md and UPGRADE.md [skip ci] --- CHANGELOG.md | 1 + UPGRADE.md | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f47ef94d9..b1aad06aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ - Enh #902: Refactor `Quoter::quoteValue()` method (@Tigrov) - New #906: Add `ServerInfoInterface` and its implementation (@Tigrov) - Enh #905: Use `AbstractColumnDefinitionBuilder` to generate table column SQL representation (@Tigrov) +- Enh #915: Remove `ColumnInterface` (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 3dc3d1ef8..b9dcdb764 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -9,16 +9,22 @@ application when you upgrade the package from one version to another. ## Upgrade from 1.x to 2.x +### Remove `ColumnInterface` + +Remove `ColumnInterface` and use `ColumnSchemaInterface` instead. + ### `ColumnSchemaInterface` as column type -Add `ColumnSchemaInterface` support and change type of parameter `$type` from `string` to `ColumnSchemaInterface|string` -in `addColumn()` method of your classes that implement the following interfaces: +Add `ColumnSchemaInterface` support and change type of parameter `$type` to `ColumnSchemaInterface|string` +in the following methods: +- `addColumn()` +- `alterColumn()` +in classes that implement the following interfaces: - `Yiisoft\Db\Command\CommandInterface`; - `Yiisoft\Db\QueryBuilder\DDLQueryBuilderInterface`; -… or inherit from the following classes: - +or inherit from the following classes: - `Yiisoft\Db\Command\AbstractCommand`; - `Yiisoft\Db\QueryBuilder\AbstractDDLQueryBuilder`; - `Yiisoft\Db\QueryBuilder\AbstractQueryBuilder`. @@ -115,11 +121,13 @@ Each table column has its own class in the `Yiisoft\Db\Schema\Column` namespace ### Remove methods +- `AbstractQueryBuilder::getColumnType()` - `AbstractDMLQueryBuilder::getTypecastValue()` - `TableSchemaInterface::compositeForeignKey()` +- `SchemaInterface::createColumn()` - `SchemaInterface::isReadQuery()` -- `AbstractSchema::isReadQuery()` - `SchemaInterface::getRawTableName()` +- `AbstractSchema::isReadQuery()` - `AbstractSchema::getRawTableName()` - `AbstractSchema::normalizeRowKeyCase()` - `Quoter::unquoteParts()`