Skip to content

Commit

Permalink
Remove ColumnInterface (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Jan 8, 2025
1 parent e4581da commit 5acbed7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Enh #274: Refactor for compatibility with `yiisoft/db` package (@Tigrov)
- Bug #277: Fix when there is a namespace but the directory does not exist (@Tigrov)
- Chg #279: Use `ColumnBuilder` class to create table column definitions (@Tigrov)
- Enh #282: Remove `ColumnInterface` (@Tigrov)

## 1.2.0 November 27, 2024

Expand Down
39 changes: 24 additions & 15 deletions src/MigrationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Builder\ColumnInterface;
use Yiisoft\Db\Migration\Informer\MigrationInformerInterface;
use Yiisoft\Db\Schema\Column\ColumnBuilder;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
Expand Down Expand Up @@ -194,7 +193,7 @@ public function delete(string $table, array|string $condition = '', array $param
* 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
Expand Down Expand Up @@ -233,7 +232,7 @@ public function createTable(string $table, array $columns, string|null $options
$this->db->createCommand()->createTable($table, $columns, $options)->execute();

foreach ($columns as $column => $type) {
if ($type instanceof ColumnInterface || $type instanceof ColumnSchemaInterface) {
if ($type instanceof ColumnSchemaInterface) {
$comment = $type->getComment();
if ($comment !== null) {
$this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute();
Expand Down Expand Up @@ -291,13 +290,18 @@ public function truncateTable(string $table): void
* @param string $table The table that the new column will be added to.
* The table name will be properly quoted by the method.
* @param string $column The name of the new column. The name will be properly quoted by the method.
* @param ColumnSchemaInterface|string $type TThe column type. The {@see QueryBuilder::buildColumnDefinition()}
* method will convert the column type into the column definition. Any column type not recognized as a database type
* will be recognized as one of an {@see ColumnType abstract} or {@see PseudoType pseudo} type, or as a 'string'
* abstract type by default to generate column definition. For example, 'string' will be generated 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}.
*/
public function addColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): void
public function addColumn(string $table, string $column, ColumnSchemaInterface|string $type): void
{
if (is_string($type)) {
$comment = null;
Expand Down Expand Up @@ -353,17 +357,22 @@ public function renameColumn(string $table, string $name, string $newName): void
*
* @param string $table The table whose column is to be changed. The method will properly quote the table name.
* @param string $column The name of the column to be changed. The name will be properly quoted by the method.
* @param ColumnSchemaInterface|string $type TThe column type. The {@see QueryBuilder::buildColumnDefinition()}
* method will convert the column type into the column definition. Any column type not recognized as a database type
* will be recognized as one of an {@see ColumnType abstract} or {@see PseudoType pseudo} type, or as a 'string'
* abstract type by default to generate column definition. For example, 'string' will be generated 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}.
*
* @throws Exception
* @throws InvalidConfigException
* @throws NotSupportedException
*/
public function alterColumn(string $table, string $column, ColumnInterface|ColumnSchemaInterface|string $type): void
public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): void
{
if (is_string($type)) {
$comment = null;
Expand Down

0 comments on commit 5acbed7

Please sign in to comment.