Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ColumnSchemaInterface to ColumnInterface #334

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions src/Column/ColumnDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand All @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions src/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/DDLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.');
}
Expand Down
10 changes: 5 additions & 5 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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'],
Expand Down
30 changes: 15 additions & 15 deletions tests/ColumnSchemaTest.php → tests/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'));
}
}
76 changes: 38 additions & 38 deletions tests/Provider/ColumnFactoryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,58 @@
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
{
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],
];
}

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;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.');
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down