Skip to content

Commit

Permalink
Rename ColumnSchemaInterface to ColumnInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Jan 9, 2025
1 parent f9976c4 commit e3177af
Show file tree
Hide file tree
Showing 46 changed files with 462 additions and 464 deletions.
35 changes: 19 additions & 16 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ application when you upgrade the package from one version to another.

### Remove `ColumnInterface`

Remove `ColumnInterface` and use `ColumnSchemaInterface` instead.
- Remove `ColumnInterface` and use `ColumnSchemaInterface` instead;
- Rename `ColumnSchemaInterface` to `ColumnInterface`.

### `ColumnSchemaInterface` as column type
### `ColumnInterface` as column type

Add `ColumnSchemaInterface` support and change type of parameter `$type` to `ColumnSchemaInterface|string`
Add `ColumnInterface` support and change type of parameter `$type` to `ColumnInterface|string`
in the following methods:
- `addColumn()`
- `alterColumn()`
Expand Down Expand Up @@ -67,7 +68,9 @@ $db->createCommand()->insertBatch('user', $values)->execute();

### `ColumnSchemaInterface` changes

The interface and the abstract implementation `AbstractColumnSchema` were moved to `Yiisoft\Db\Schema\Column` namespace
Rename `ColumnSchemaInterface` to `ColumnInterface`.

The interface and the abstract implementation `AbstractColumn` were moved to `Yiisoft\Db\Schema\Column` namespace
and the following changes were made:

- `getName()` method can return `string` or `null`;
Expand All @@ -83,8 +86,8 @@ and the following changes were made:
- `unique(bool $unique = true)` method is added;
- `isUnique()` method is added;
- `hasDefaultValue()` method is added;
- all `AbstractColumnSchema` class properties except `$type` moved to constructor;
- added `DEFAULT_TYPE` constant to `AbstractColumnSchema` class;
- all `AbstractColumn` class properties except `$type` moved to constructor;
- added `DEFAULT_TYPE` constant to `AbstractColumn` class;
- added method chaining.

### New classes with constants
Expand All @@ -98,16 +101,16 @@ and the following changes were made:

Each table column has its own class in the `Yiisoft\Db\Schema\Column` namespace according to the data type:

- `BooleanColumnSchema` for columns with boolean type;
- `BitColumnSchema` for columns with bit type;
- `IntegerColumnSchema` for columns with integer type (tinyint, smallint, integer, bigint);
- `BigIntColumnSchema` for columns with integer type with range outside `PHP_INT_MIN` and `PHP_INT_MAX`;
- `DoubleColumnSchema` for columns with fractional number type (float, double, decimal, money);
- `StringColumnSchema` for columns with string or datetime type (char, string, text, datetime, timestamp, date, time);
- `BinaryColumnSchema` for columns with binary type;
- `ArrayColumnSchema` for columns with array type;
- `StructuredColumnSchema` for columns with structured type (composite type in PostgreSQL);
- `JsonColumnSchema` for columns with json type.
- `BooleanColumn` for columns with boolean type;
- `BitColumn` for columns with bit type;
- `IntegerColumn` for columns with integer type (tinyint, smallint, integer, bigint);
- `BigIntColumn` for columns with integer type with range outside `PHP_INT_MIN` and `PHP_INT_MAX`;
- `DoubleColumn` for columns with fractional number type (float, double, decimal, money);
- `StringColumn` for columns with string or datetime type (char, string, text, datetime, timestamp, date, time);
- `BinaryColumn` for columns with binary type;
- `ArrayColumn` for columns with array type;
- `StructuredColumn` for columns with structured type (composite type in PostgreSQL);
- `JsonColumn` for columns with json type.

### New methods

Expand Down
6 changes: 3 additions & 3 deletions docs/guide/en/schema/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ echo $tableSchema->getCreateSql();
In the full name is a table name prefixed by database schema.
If the schema name is the same as the default schema, the full name won't include the schema name.

### Retrieving column schemas
### Retrieving table columns

You can retrieve the column metadata for a given table using either the `getColumns()` method or `getColumn()` method
of `TableSchema` class:
Expand All @@ -95,5 +95,5 @@ $column = $tableSchema->getColumn('id');
echo 'id (' . $column->getDbType() . ')';
```

In either case you get instance or instances
or `ColumnSchemaInterface` that you can use to get all the information about the column.
In either case you get instance or instances of `ColumnInterface` that you can use to get available information about
the column.
6 changes: 3 additions & 3 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

use function explode;
use function get_resource_type;
Expand Down Expand Up @@ -131,7 +131,7 @@ public function addCheck(string $table, string $name, string $expression): stati
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

public function addColumn(string $table, string $column, ColumnSchemaInterface|string $type): static
public function addColumn(string $table, string $column, ColumnInterface|string $type): static
{
$sql = $this->getQueryBuilder()->addColumn($table, $column, $type);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
Expand Down Expand Up @@ -188,7 +188,7 @@ public function addUnique(string $table, string $name, array|string $columns): s
return $this->setSql($sql)->requireTableSchemaRefresh($table);
}

public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): static
public function alterColumn(string $table, string $column, ColumnInterface|string $type): static
{
$sql = $this->getQueryBuilder()->alterColumn($table, $column, $type);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
Expand Down
20 changes: 10 additions & 10 deletions src/Command/CommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Yiisoft\Db\Query\Data\DataReaderInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\DMLQueryBuilderInterface;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

/**
* This interface represents a database command, such as a `SELECT`, `INSERT`, `UPDATE`, or `DELETE` statement.
Expand Down Expand Up @@ -46,13 +46,13 @@ public function addCheck(string $table, string $name, string $expression): stati
*
* @param string $table The name of the table to add new column to.
* @param string $column The name of the new column.
* @param ColumnSchemaInterface|string $type The column type.
* @param ColumnInterface|string $type The column type.
* {@see QueryBuilder::buildColumnDefinition()} will be called to convert the given column type to the database one.
* For example, `string` will be converted to `varchar(255)`, and `string not null` becomes `varchar(255) not null`.
*
* Note: The method will quote the `table` and `column` parameters before using them in the generated SQL.
*/
public function addColumn(string $table, string $column, ColumnSchemaInterface|string $type): static;
public function addColumn(string $table, string $column, ColumnInterface|string $type): static;

/**
* Builds an SQL command for adding a comment to a column.
Expand Down Expand Up @@ -146,13 +146,13 @@ public function addPrimaryKey(string $table, string $name, array|string $columns
*
* @param string $table The table whose column is to change.
* @param string $column The name of the column to change.
* @param ColumnSchemaInterface|string $type The column type.
* @param ColumnInterface|string $type The column type.
* {@see QueryBuilder::buildColumnDefinition()} will be called to convert the give column type to the physical one.
* For example, `string` will be converted as `varchar(255)`, and `string not null` becomes `varchar(255) not null`.
*
* Note: The method will quote the `table` and `column` parameters before using them in the generated SQL.
*/
public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): static;
public function alterColumn(string $table, string $column, ColumnInterface|string $type): static;

/**
* Creates a batch INSERT command.
Expand Down Expand Up @@ -319,14 +319,14 @@ public function createIndex(
* The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'), where name
* is the name of the column which will be properly quoted by the method, and definition is the type of the column
* 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}.
* or can be represented as instance of {@see ColumnInterface}.
*
* 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}.
* {@see ColumnInterface}.
*
* ```php
* $this->createTable(
Expand All @@ -348,8 +348,8 @@ public function createIndex(
* generated SQL.
*
* @param string $table The name of the table to create.
* @param (ColumnSchemaInterface|string)[] $columns The columns (name => definition) in the new table.
* The definition can be `string` or {@see ColumnSchemaInterface} instance.
* @param (ColumnInterface|string)[] $columns The columns (name => definition) in the new table.
* The definition can be `string` or {@see ColumnInterface} instance.
* @param string|null $options More SQL fragments to append to the generated SQL.
*
* @throws Exception
Expand All @@ -358,7 +358,7 @@ public function createIndex(
*
* Note: The method will quote the `table` and `columns` parameter before using it in the generated SQL.
*
* @psalm-param array<string, ColumnSchemaInterface>|string[] $columns
* @psalm-param array<string, ColumnInterface>|string[] $columns
*/
public function createTable(string $table, array $columns, string $options = null): static;

Expand Down
4 changes: 2 additions & 2 deletions src/Constant/PhpType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Yiisoft\Db\Constant;

use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

/**
* Defines the available PHP types.
* Used to generate properties of a related model class.
*
* @see ColumnSchemaInterface::getPhpType()
* @see ColumnInterface::getPhpType()
* @see https://www.php.net/manual/en/language.types.type-system.php
*/
final class PhpType
Expand Down
6 changes: 3 additions & 3 deletions src/Debug/CommandInterfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Yiisoft\Db\Command\CommandInterface;
use Yiisoft\Db\Query\Data\DataReaderInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

final class CommandInterfaceProxy implements CommandInterface
{
Expand All @@ -30,7 +30,7 @@ public function addCheck(string $table, string $name, string $expression): stati
/**
* @psalm-suppress MixedArgument
*/
public function addColumn(string $table, string $column, ColumnSchemaInterface|string $type): static
public function addColumn(string $table, string $column, ColumnInterface|string $type): static
{
return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public function addUnique(string $table, string $name, array|string $columns): s
/**
* @psalm-suppress MixedArgument
*/
public function alterColumn(string $table, string $column, ColumnSchemaInterface|string $type): static
public function alterColumn(string $table, string $column, ColumnInterface|string $type): static
{
return new self($this->decorated->{__FUNCTION__}(...func_get_args()), $this->collector);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Expression/StructuredExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Yiisoft\Db\Expression;

use Traversable;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;

use function array_key_exists;
use function array_keys;
Expand Down Expand Up @@ -38,10 +38,10 @@ final class StructuredExpression implements ExpressionInterface
* @param string|null $type The structured database type name. Defaults to `null` which means the type is not
* explicitly specified. Note that in the case where a type is not specified explicitly and DBMS cannot guess it
* from the context, SQL error will be raised.
* @param ColumnSchemaInterface[] $columns The structured type columns that are used for value normalization and type
* @param ColumnInterface[] $columns The structured type columns that are used for value normalization and type
* casting.
*
* @psalm-param array<string, ColumnSchemaInterface> $columns
* @psalm-param array<string, ColumnInterface> $columns
*/
public function __construct(
private array|object $value,
Expand All @@ -66,7 +66,7 @@ public function getType(): string|null
/**
* The structured type columns that are used for value normalization and type casting.
*
* @return ColumnSchemaInterface[]
* @return ColumnInterface[]
*/
public function getColumns(): array
{
Expand Down
Loading

0 comments on commit e3177af

Please sign in to comment.