From 5e75c147fc9b2ce022db474980f19168b119976e Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Wed, 8 Jan 2025 10:21:19 +0700 Subject: [PATCH] Remove `ColumnInterface` (#371) --- CHANGELOG.md | 1 + src/Column.php | 70 ------------------- src/QueryBuilder.php | 32 --------- src/Schema.php | 9 --- tests/ColumnSchemaBuilderTest.php | 26 ------- .../Provider/ColumnSchemaBuilderProvider.php | 39 ----------- 6 files changed, 1 insertion(+), 176 deletions(-) delete mode 100644 src/Column.php delete mode 100644 tests/ColumnSchemaBuilderTest.php delete mode 100644 tests/Provider/ColumnSchemaBuilderProvider.php diff --git a/CHANGELOG.md b/CHANGELOG.md index e121b0d51..1d34010b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Enh #366: Refactor `Quoter::quoteValue()` method (@Tigrov) - Chg #368: Update `QueryBuilder` constructor (@Tigrov) - Enh #367: Use `ColumnDefinitionBuilder` to generate table column SQL representation (@Tigrov) +- Enh #371: Remove `ColumnInterface` (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/Column.php b/src/Column.php deleted file mode 100644 index f722420db..000000000 --- a/src/Column.php +++ /dev/null @@ -1,70 +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. - * - * @psalm-suppress DeprecatedClass - * - * @deprecated Use {@see StringColumnSchema} or other column classes instead. Will be removed in 2.0.0. - */ -final class Column extends AbstractColumn -{ - /** - * Builds the unsigned string for column. Defaults to unsupported. - * - * @return string A string containing `UNSIGNED` keyword. - */ - protected function buildUnsignedString(): string - { - return $this->isUnsigned() ? ' UNSIGNED' : ''; - } - - /** - * Builds the comment specification for the column. - * - * @throws Exception - * - * @return string A string containing the `COMMENT` keyword and the comment itself. - */ - protected function buildCommentString(): string - { - if ($this->getComment() === null) { - return ''; - } - - return ' COMMENT ' . (new Quoter('`', '`'))->quoteValue($this->getComment() ?? ''); - } - - public function asString(): string - { - $format = match ($this->getTypeCategory()) { - self::TYPE_CATEGORY_PK => '{type}{length}{comment}{check}{append}', - self::TYPE_CATEGORY_NUMERIC => '{type}{length}{unsigned}{notnull}{default}{unique}{comment}{append}{check}', - self::TYPE_CATEGORY_UUID => '{type}{notnull}{unique}{default}{check}{comment}{append}', - self::TYPE_CATEGORY_UUID_PK => '{type}{notnull}{default}{check}{comment}{append}', - default => '{type}{length}{notnull}{default}{unique}{comment}{append}{check}', - }; - - return $this->buildCompleteString($format); - } -} diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 23986e97d..0cbdd963c 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -5,8 +5,6 @@ namespace Yiisoft\Db\Mysql; use Yiisoft\Db\Connection\ServerInfoInterface; -use Yiisoft\Db\Constant\ColumnType; -use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Mysql\Column\ColumnDefinitionBuilder; use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder; use Yiisoft\Db\Schema\QuoterInterface; @@ -17,36 +15,6 @@ */ final class QueryBuilder extends AbstractQueryBuilder { - /** - * @psalm-var string[] $typeMap Mapping from abstract column types (keys) to physical column types (values). - */ - protected array $typeMap = [ - PseudoType::PK => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY', - PseudoType::UPK => 'int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', - PseudoType::BIGPK => 'bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY', - PseudoType::UBIGPK => 'bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', - ColumnType::CHAR => 'char(1)', - ColumnType::STRING => 'varchar(255)', - ColumnType::TEXT => 'text', - ColumnType::TINYINT => 'tinyint(3)', - ColumnType::SMALLINT => 'smallint(6)', - ColumnType::INTEGER => 'int(11)', - ColumnType::BIGINT => 'bigint(20)', - ColumnType::FLOAT => 'float', - ColumnType::DOUBLE => 'double', - ColumnType::DECIMAL => 'decimal(10,0)', - ColumnType::DATE => 'date', - ColumnType::BINARY => 'blob', - ColumnType::BOOLEAN => 'bit(1)', - ColumnType::MONEY => 'decimal(19,4)', - ColumnType::JSON => 'json', - ColumnType::DATETIME => 'datetime(0)', - ColumnType::TIMESTAMP => 'timestamp(0)', - ColumnType::TIME => 'time(0)', - ColumnType::UUID => 'binary(16)', - PseudoType::UUID_PK => 'binary(16) PRIMARY KEY', - ]; - public function __construct(QuoterInterface $quoter, SchemaInterface $schema, ServerInfoInterface $serverInfo) { parent::__construct( diff --git a/src/Schema.php b/src/Schema.php index f0c4eba1a..6afb59e55 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -14,9 +14,7 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Helper\DbArrayHelper; -use Yiisoft\Db\Mysql\Column\ColumnBuilder; use Yiisoft\Db\Mysql\Column\ColumnFactory; -use Yiisoft\Db\Schema\Builder\ColumnInterface; use Yiisoft\Db\Schema\Column\ColumnFactoryInterface; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\TableSchemaInterface; @@ -73,13 +71,6 @@ */ final class Schema extends AbstractPdoSchema { - /** @deprecated Use {@see ColumnBuilder} instead. Will be removed in 2.0. */ - public function createColumn(string $type, array|int|string $length = null): ColumnInterface - { - /** @psalm-suppress DeprecatedClass */ - return new Column($type, $length); - } - public function getColumnFactory(): ColumnFactoryInterface { return new ColumnFactory(); diff --git a/tests/ColumnSchemaBuilderTest.php b/tests/ColumnSchemaBuilderTest.php deleted file mode 100644 index 490b613a6..000000000 --- a/tests/ColumnSchemaBuilderTest.php +++ /dev/null @@ -1,26 +0,0 @@ -checkBuildString($expected, $type, $length, $calls); - } -} diff --git a/tests/Provider/ColumnSchemaBuilderProvider.php b/tests/Provider/ColumnSchemaBuilderProvider.php deleted file mode 100644 index a6771a316..000000000 --- a/tests/Provider/ColumnSchemaBuilderProvider.php +++ /dev/null @@ -1,39 +0,0 @@ -