diff --git a/CHANGELOG.md b/CHANGELOG.md index d07218de..28c29bd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Chg #330: Update `QueryBuilder` constructor (@Tigrov) - Enh #329: Use `ColumnDefinitionBuilder` to generate table column SQL representation (@Tigrov) - Enh #332: Remove `ColumnInterface` (@Tigrov) +- Enh #334: Rename `ColumnSchemaInterface` to `ColumnInterface` (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/Column/ColumnDefinitionBuilder.php b/src/Column/ColumnDefinitionBuilder.php index 4445f8b6..c141aa33 100644 --- a/src/Column/ColumnDefinitionBuilder.php +++ b/src/Column/ColumnDefinitionBuilder.php @@ -6,7 +6,7 @@ use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\QueryBuilder\AbstractColumnDefinitionBuilder; -use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; +use Yiisoft\Db\Schema\Column\ColumnInterface; final class ColumnDefinitionBuilder extends AbstractColumnDefinitionBuilder { @@ -42,7 +42,7 @@ final class ColumnDefinitionBuilder extends AbstractColumnDefinitionBuilder 'numeric', ]; - public function build(ColumnSchemaInterface $column): string + public function build(ColumnInterface $column): string { return $this->buildType($column) . $this->buildPrimaryKey($column) @@ -56,19 +56,19 @@ public function build(ColumnSchemaInterface $column): string . $this->buildComment($column); } - protected function buildComment(ColumnSchemaInterface $column): string + protected function buildComment(ColumnInterface $column): string { $comment = $column->getComment(); return $comment === null || $comment === '' ? '' : ' /* ' . str_replace('*/', '*\/', $comment) . ' */'; } - protected function buildNotNull(ColumnSchemaInterface $column): string + protected function buildNotNull(ColumnInterface $column): string { return $column->isPrimaryKey() ? ' NOT NULL' : parent::buildNotNull($column); } - protected function getDbType(ColumnSchemaInterface $column): string + protected function getDbType(ColumnInterface $column): string { /** @psalm-suppress DocblockTypeContradiction */ return $column->getDbType() ?? match ($column->getType()) { diff --git a/src/Column/ColumnFactory.php b/src/Column/ColumnFactory.php index 22a748b3..fc2675cd 100644 --- a/src/Column/ColumnFactory.php +++ b/src/Column/ColumnFactory.php @@ -6,7 +6,7 @@ use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Schema\Column\AbstractColumnFactory; -use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; +use Yiisoft\Db\Schema\Column\ColumnInterface; use function str_replace; use function substr; @@ -60,7 +60,7 @@ protected function getType(string $dbType, array $info = []): string }; } - protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnSchemaInterface $column): mixed + protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnInterface $column): mixed { if ($defaultValue[0] === '"' && $defaultValue[-1] === '"') { $value = substr($defaultValue, 1, -1); diff --git a/src/DDLQueryBuilder.php b/src/DDLQueryBuilder.php index 195812e7..fcf1e6ec 100644 --- a/src/DDLQueryBuilder.php +++ b/src/DDLQueryBuilder.php @@ -6,8 +6,7 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\QueryBuilder\AbstractDDLQueryBuilder; -use Yiisoft\Db\Schema\Builder\ColumnInterface; -use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; +use Yiisoft\Db\Schema\Column\ColumnInterface; use function count; @@ -82,7 +81,7 @@ public function addUnique(string $table, string $name, array|string $columns): s /** * @throws NotSupportedException SQLite doesn't support this method. */ - public function alterColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): string + public function alterColumn(string $table, string $column, ColumnInterface|string $type): string { throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); } diff --git a/src/Schema.php b/src/Schema.php index fc505143..7c09a6c4 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -17,7 +17,7 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Helper\DbArrayHelper; use Yiisoft\Db\Schema\Column\ColumnFactoryInterface; -use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; +use Yiisoft\Db\Schema\Column\ColumnInterface; use Yiisoft\Db\Schema\TableSchemaInterface; use Yiisoft\Db\Sqlite\Column\ColumnFactory; @@ -336,7 +336,7 @@ protected function findColumns(TableSchemaInterface $table): bool $info['schema'] = $table->getSchemaName(); $info['table'] = $table->getName(); - $column = $this->loadColumnSchema($info); + $column = $this->loadColumn($info); $table->column($info['name'], $column); if ($column->isPrimaryKey()) { @@ -430,15 +430,15 @@ public function getSchemaDefaultValues(string $schema = '', bool $refresh = fals } /** - * Loads the column information into a {@see ColumnSchemaInterface} object. + * Loads the column information into a {@see ColumnInterface} object. * * @param array $info The column information. * - * @return ColumnSchemaInterface The column schema object. + * @return ColumnInterface The column object. * * @psalm-param ColumnInfo $info */ - private function loadColumnSchema(array $info): ColumnSchemaInterface + private function loadColumn(array $info): ColumnInterface { return $this->getColumnFactory()->fromDefinition($info['type'], [ 'defaultValueRaw' => $info['dflt_value'], diff --git a/tests/ColumnSchemaTest.php b/tests/ColumnTest.php similarity index 74% rename from tests/ColumnSchemaTest.php rename to tests/ColumnTest.php index e942084b..ade53787 100644 --- a/tests/ColumnSchemaTest.php +++ b/tests/ColumnTest.php @@ -6,22 +6,22 @@ use PDO; use Yiisoft\Db\Command\Param; -use Yiisoft\Db\Schema\Column\BinaryColumnSchema; -use Yiisoft\Db\Schema\Column\BooleanColumnSchema; -use Yiisoft\Db\Schema\Column\DoubleColumnSchema; -use Yiisoft\Db\Schema\Column\IntegerColumnSchema; -use Yiisoft\Db\Schema\Column\JsonColumnSchema; -use Yiisoft\Db\Schema\Column\StringColumnSchema; +use Yiisoft\Db\Schema\Column\BinaryColumn; +use Yiisoft\Db\Schema\Column\BooleanColumn; +use Yiisoft\Db\Schema\Column\DoubleColumn; +use Yiisoft\Db\Schema\Column\IntegerColumn; +use Yiisoft\Db\Schema\Column\JsonColumn; +use Yiisoft\Db\Schema\Column\StringColumn; use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; use Yiisoft\Db\Query\Query; -use Yiisoft\Db\Tests\Common\CommonColumnSchemaTest; +use Yiisoft\Db\Tests\Common\CommonColumnTest; use function str_repeat; /** * @group sqlite */ -final class ColumnSchemaTest extends CommonColumnSchemaTest +final class ColumnTest extends CommonColumnTest { use TestTrait; @@ -78,17 +78,17 @@ public function testPhpTypeCast(): void $db->close(); } - public function testColumnSchemaInstance() + public function testColumnInstance() { $db = $this->getConnection(true); $schema = $db->getSchema(); $tableSchema = $schema->getTableSchema('type'); - $this->assertInstanceOf(IntegerColumnSchema::class, $tableSchema->getColumn('int_col')); - $this->assertInstanceOf(StringColumnSchema::class, $tableSchema->getColumn('char_col')); - $this->assertInstanceOf(DoubleColumnSchema::class, $tableSchema->getColumn('float_col')); - $this->assertInstanceOf(BinaryColumnSchema::class, $tableSchema->getColumn('blob_col')); - $this->assertInstanceOf(BooleanColumnSchema::class, $tableSchema->getColumn('bool_col')); - $this->assertInstanceOf(JsonColumnSchema::class, $tableSchema->getColumn('json_col')); + $this->assertInstanceOf(IntegerColumn::class, $tableSchema->getColumn('int_col')); + $this->assertInstanceOf(StringColumn::class, $tableSchema->getColumn('char_col')); + $this->assertInstanceOf(DoubleColumn::class, $tableSchema->getColumn('float_col')); + $this->assertInstanceOf(BinaryColumn::class, $tableSchema->getColumn('blob_col')); + $this->assertInstanceOf(BooleanColumn::class, $tableSchema->getColumn('bool_col')); + $this->assertInstanceOf(JsonColumn::class, $tableSchema->getColumn('json_col')); } } diff --git a/tests/Provider/ColumnFactoryProvider.php b/tests/Provider/ColumnFactoryProvider.php index 4fd412a0..2b498586 100644 --- a/tests/Provider/ColumnFactoryProvider.php +++ b/tests/Provider/ColumnFactoryProvider.php @@ -5,13 +5,13 @@ namespace Yiisoft\Db\Sqlite\Tests\Provider; use Yiisoft\Db\Constant\ColumnType; -use Yiisoft\Db\Schema\Column\BinaryColumnSchema; -use Yiisoft\Db\Schema\Column\BitColumnSchema; -use Yiisoft\Db\Schema\Column\BooleanColumnSchema; -use Yiisoft\Db\Schema\Column\DoubleColumnSchema; -use Yiisoft\Db\Schema\Column\IntegerColumnSchema; -use Yiisoft\Db\Schema\Column\JsonColumnSchema; -use Yiisoft\Db\Schema\Column\StringColumnSchema; +use Yiisoft\Db\Schema\Column\BinaryColumn; +use Yiisoft\Db\Schema\Column\BitColumn; +use Yiisoft\Db\Schema\Column\BooleanColumn; +use Yiisoft\Db\Schema\Column\DoubleColumn; +use Yiisoft\Db\Schema\Column\IntegerColumn; +use Yiisoft\Db\Schema\Column\JsonColumn; +use Yiisoft\Db\Schema\Column\StringColumn; final class ColumnFactoryProvider extends \Yiisoft\Db\Tests\Provider\ColumnFactoryProvider { @@ -19,35 +19,35 @@ public static function dbTypes(): array { return [ // db type, expected abstract type, expected instance of - ['bool', ColumnType::BOOLEAN, BooleanColumnSchema::class], - ['boolean', ColumnType::BOOLEAN, BooleanColumnSchema::class], - ['bit', ColumnType::BIT, BitColumnSchema::class], - ['tinyint', ColumnType::TINYINT, IntegerColumnSchema::class], - ['smallint', ColumnType::SMALLINT, IntegerColumnSchema::class], - ['mediumint', ColumnType::INTEGER, IntegerColumnSchema::class], - ['int', ColumnType::INTEGER, IntegerColumnSchema::class], - ['integer', ColumnType::INTEGER, IntegerColumnSchema::class], - ['bigint', ColumnType::BIGINT, IntegerColumnSchema::class], - ['float', ColumnType::FLOAT, DoubleColumnSchema::class], - ['real', ColumnType::FLOAT, DoubleColumnSchema::class], - ['double', ColumnType::DOUBLE, DoubleColumnSchema::class], - ['decimal', ColumnType::DECIMAL, DoubleColumnSchema::class], - ['numeric', ColumnType::DECIMAL, DoubleColumnSchema::class], - ['char', ColumnType::CHAR, StringColumnSchema::class], - ['varchar', ColumnType::STRING, StringColumnSchema::class], - ['string', ColumnType::STRING, StringColumnSchema::class], - ['enum', ColumnType::STRING, StringColumnSchema::class], - ['tinytext', ColumnType::TEXT, StringColumnSchema::class], - ['mediumtext', ColumnType::TEXT, StringColumnSchema::class], - ['longtext', ColumnType::TEXT, StringColumnSchema::class], - ['text', ColumnType::TEXT, StringColumnSchema::class], - ['blob', ColumnType::BINARY, BinaryColumnSchema::class], - ['year', ColumnType::DATE, StringColumnSchema::class], - ['date', ColumnType::DATE, StringColumnSchema::class], - ['time', ColumnType::TIME, StringColumnSchema::class], - ['datetime', ColumnType::DATETIME, StringColumnSchema::class], - ['timestamp', ColumnType::TIMESTAMP, StringColumnSchema::class], - ['json', ColumnType::JSON, JsonColumnSchema::class], + ['bool', ColumnType::BOOLEAN, BooleanColumn::class], + ['boolean', ColumnType::BOOLEAN, BooleanColumn::class], + ['bit', ColumnType::BIT, BitColumn::class], + ['tinyint', ColumnType::TINYINT, IntegerColumn::class], + ['smallint', ColumnType::SMALLINT, IntegerColumn::class], + ['mediumint', ColumnType::INTEGER, IntegerColumn::class], + ['int', ColumnType::INTEGER, IntegerColumn::class], + ['integer', ColumnType::INTEGER, IntegerColumn::class], + ['bigint', ColumnType::BIGINT, IntegerColumn::class], + ['float', ColumnType::FLOAT, DoubleColumn::class], + ['real', ColumnType::FLOAT, DoubleColumn::class], + ['double', ColumnType::DOUBLE, DoubleColumn::class], + ['decimal', ColumnType::DECIMAL, DoubleColumn::class], + ['numeric', ColumnType::DECIMAL, DoubleColumn::class], + ['char', ColumnType::CHAR, StringColumn::class], + ['varchar', ColumnType::STRING, StringColumn::class], + ['string', ColumnType::STRING, StringColumn::class], + ['enum', ColumnType::STRING, StringColumn::class], + ['tinytext', ColumnType::TEXT, StringColumn::class], + ['mediumtext', ColumnType::TEXT, StringColumn::class], + ['longtext', ColumnType::TEXT, StringColumn::class], + ['text', ColumnType::TEXT, StringColumn::class], + ['blob', ColumnType::BINARY, BinaryColumn::class], + ['year', ColumnType::DATE, StringColumn::class], + ['date', ColumnType::DATE, StringColumn::class], + ['time', ColumnType::TIME, StringColumn::class], + ['datetime', ColumnType::DATETIME, StringColumn::class], + ['timestamp', ColumnType::TIMESTAMP, StringColumn::class], + ['json', ColumnType::JSON, JsonColumn::class], ]; } @@ -55,8 +55,8 @@ public static function definitions(): array { $definitions = parent::definitions(); - $definitions[] = ['bit(1)', ColumnType::BOOLEAN, BooleanColumnSchema::class, ['getDbType' => 'bit', 'getSize' => 1]]; - $definitions[] = ['tinyint(1)', ColumnType::BOOLEAN, BooleanColumnSchema::class, ['getDbType' => 'tinyint', 'getSize' => 1]]; + $definitions[] = ['bit(1)', ColumnType::BOOLEAN, BooleanColumn::class, ['getDbType' => 'bit', 'getSize' => 1]]; + $definitions[] = ['tinyint(1)', ColumnType::BOOLEAN, BooleanColumn::class, ['getDbType' => 'tinyint', 'getSize' => 1]]; return $definitions; } diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index b7d5ac97..e5534ff4 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -16,7 +16,7 @@ use Yiisoft\Db\Query\Query; use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\QueryBuilder\Condition\JsonOverlapsCondition; -use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; +use Yiisoft\Db\Schema\Column\ColumnInterface; use Yiisoft\Db\Sqlite\Column\ColumnBuilder; use Yiisoft\Db\Sqlite\Tests\Provider\QueryBuilderProvider; use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; @@ -167,7 +167,7 @@ public function testAddUnique(string $name, string $table, array|string $columns } #[DataProviderExternal(QueryBuilderProvider::class, 'alterColumn')] - public function testAlterColumn(string|ColumnSchemaInterface $type, string $expected): void + public function testAlterColumn(string|ColumnInterface $type, string $expected): void { $this->expectException(NotSupportedException::class); $this->expectExceptionMessage('Yiisoft\Db\Sqlite\DDLQueryBuilder::alterColumn is not supported by SQLite.'); @@ -837,7 +837,7 @@ public function testJsonOverlapsConditionOperator(iterable|ExpressionInterface $ } #[DataProviderExternal(QueryBuilderProvider::class, 'buildColumnDefinition')] - public function testBuildColumnDefinition(string $expected, ColumnSchemaInterface|string $column): void + public function testBuildColumnDefinition(string $expected, ColumnInterface|string $column): void { parent::testBuildColumnDefinition($expected, $column); } diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 37bc703f..2d316e28 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -39,17 +39,17 @@ public function testColumnComment(): void /** * @dataProvider \Yiisoft\Db\Sqlite\Tests\Provider\SchemaProvider::columns */ - public function testColumnSchema(array $columns, string $tableName): void + public function testColumns(array $columns, string $tableName): void { - parent::testColumnSchema($columns, $tableName); + parent::testColumns($columns, $tableName); } /** * @dataProvider \Yiisoft\Db\Sqlite\Tests\Provider\SchemaProvider::columnsTypeBit */ - public function testColumnSchemaWithTypeBit(array $columns): void + public function testColumnWithTypeBit(array $columns): void { - $this->columnSchema($columns, 'type_bit'); + $this->assertTableColumns($columns, 'type_bit'); } /**