From 87f8e1a2ee8350d7bf8528726733966e0d82e89f Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 8 Nov 2024 08:24:05 +0700 Subject: [PATCH] Use new column definition builder --- src/Column.php | 4 +++ src/DDLQueryBuilder.php | 6 ++-- src/Schema.php | 1 + tests/ColumnSchemaBuilderTest.php | 8 ----- .../Provider/ColumnSchemaBuilderProvider.php | 19 ---------- tests/Provider/QueryBuilderProvider.php | 8 +++++ tests/QueryBuilderTest.php | 36 +++++++------------ 7 files changed, 29 insertions(+), 53 deletions(-) diff --git a/src/Column.php b/src/Column.php index 51efdc13..be6dc324 100644 --- a/src/Column.php +++ b/src/Column.php @@ -20,6 +20,10 @@ * * 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 { diff --git a/src/DDLQueryBuilder.php b/src/DDLQueryBuilder.php index 972dcd3c..0b3d7048 100644 --- a/src/DDLQueryBuilder.php +++ b/src/DDLQueryBuilder.php @@ -8,6 +8,7 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\QueryBuilder\AbstractDDLQueryBuilder; use Yiisoft\Db\Schema\Builder\ColumnInterface; +use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; /** * Implements a (Data Definition Language) SQL statements for Oracle Server. @@ -45,14 +46,13 @@ public function addForeignKey( return $sql; } - public function alterColumn(string $table, string $column, ColumnInterface|string $type): string + public function alterColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): string { - /** @psalm-suppress DeprecatedMethod */ return 'ALTER TABLE ' . $this->quoter->quoteTableName($table) . ' MODIFY ' . $this->quoter->quoteColumnName($column) - . ' ' . $this->queryBuilder->getColumnType($type); + . ' ' . $this->queryBuilder->buildColumnDefinition($type); } public function checkIntegrity(string $schema = '', string $table = '', bool $check = true): string diff --git a/src/Schema.php b/src/Schema.php index b2364ea7..736968f2 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -73,6 +73,7 @@ public function __construct(protected ConnectionInterface $db, SchemaCache $sche /** @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); } diff --git a/tests/ColumnSchemaBuilderTest.php b/tests/ColumnSchemaBuilderTest.php index c6c46c34..41150090 100644 --- a/tests/ColumnSchemaBuilderTest.php +++ b/tests/ColumnSchemaBuilderTest.php @@ -23,12 +23,4 @@ public function testCustomTypes(string $expected, string $type, int|null $length { $this->checkBuildString($expected, $type, $length, $calls); } - - /** - * @dataProvider \Yiisoft\Db\Oracle\Tests\Provider\ColumnSchemaBuilderProvider::createColumnTypes - */ - public function testCreateColumnTypes(string $expected, string $type, ?int $length, array $calls): void - { - parent::testCreateColumnTypes($expected, $type, $length, $calls); - } } diff --git a/tests/Provider/ColumnSchemaBuilderProvider.php b/tests/Provider/ColumnSchemaBuilderProvider.php index 9c065cf4..b157b445 100644 --- a/tests/Provider/ColumnSchemaBuilderProvider.php +++ b/tests/Provider/ColumnSchemaBuilderProvider.php @@ -22,23 +22,4 @@ public static function types(): array ['integer UNSIGNED', ColumnType::INTEGER, null, [['unsigned']]], ]; } - - public static function createColumnTypes(): array - { - $types = parent::createColumnTypes(); - $types['integer'][0] = '"column" NUMBER(10)'; - - $types['uuid'][0] = '"column" RAW(16)'; - $types['uuid not null'][0] = '"column" RAW(16) NOT NULL'; - - $types['uuid with default'][0] = '"column" RAW(16) DEFAULT HEXTORAW(REGEXP_REPLACE(\'875343b3-6bd0-4bec-81bb-aa68bb52d945\', \'-\', \'\'))'; - $types['uuid with default'][3] = [['defaultExpression', 'HEXTORAW(REGEXP_REPLACE(\'875343b3-6bd0-4bec-81bb-aa68bb52d945\', \'-\', \'\'))']]; - - $types['uuid pk'][0] = '"column" RAW(16) DEFAULT SYS_GUID() PRIMARY KEY'; - $types['uuid pk not null'][0] = '"column" RAW(16) DEFAULT SYS_GUID() PRIMARY KEY NOT NULL'; - $types['uuid pk not null with default'][0] = '"column" RAW(16) DEFAULT SYS_GUID() PRIMARY KEY NOT NULL'; - $types['uuid pk not null with default'][3] = [['notNull']]; - - return $types; - } } diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 731a7997..4655bb23 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Oracle\Tests\Provider; use Exception; +use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Constraint\ForeignKeyConstraint; use Yiisoft\Db\Expression\Expression; @@ -44,6 +45,13 @@ public static function addForeignKey(): array return $addForeingKey; } + public static function alterColumn(): array + { + return [ + [ColumnType::STRING, 'ALTER TABLE "foo1" MODIFY "bar" varchar2(255)'], + ]; + } + public static function batchInsert(): array { $batchInsert = parent::batchInsert(); diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 75ce0b61..10859887 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -6,7 +6,6 @@ use PHPUnit\Framework\Attributes\DataProviderExternal; use Throwable; -use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; @@ -28,6 +27,11 @@ final class QueryBuilderTest extends CommonQueryBuilderTest { use TestTrait; + public function getBuildColumnDefinitionProvider(): array + { + return QueryBuilderProvider::buildColumnDefinition(); + } + /** * @throws Exception * @throws InvalidConfigException @@ -99,24 +103,10 @@ public function testAddUnique(string $name, string $table, array|string $columns parent::testAddUnique($name, $table, $columns, $expected); } - /** - * @throws Exception - * @throws InvalidConfigException - */ - public function testAlterColumn(): void + #[DataProviderExternal(QueryBuilderProvider::class, 'alterColumn')] + public function testAlterColumn(string|ColumnSchemaInterface $type, string $expected): void { - $db = $this->getConnection(); - - $qb = $db->getQueryBuilder(); - - $this->assertSame( - <<alterColumn('customer', 'email', ColumnType::STRING), - ); - - $db->close(); + parent::testAlterColumn($type, $expected); } /** @@ -312,11 +302,11 @@ public function testCreateTable(): void $this->assertSame( <<createTable(