Skip to content
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
5 changes: 2 additions & 3 deletions src/Db/Action/AddColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Migrations\Db\Action;

use Migrations\Db\Literal;
use Migrations\Db\Table\Column;
use Migrations\Db\Table\TableMetadata;

Expand Down Expand Up @@ -38,11 +37,11 @@ public function __construct(TableMetadata $table, Column $column)
*
* @param \Migrations\Db\Table\TableMetadata $table The table to add the column to
* @param string $columnName The column name
* @param string|\Migrations\Db\Literal $type The column type
* @param string $type The column type
* @param array<string, mixed> $options The column options
* @return self
*/
public static function build(TableMetadata $table, string $columnName, string|Literal $type, array $options = []): self
public static function build(TableMetadata $table, string $columnName, string $type, array $options = []): self
{
$column = new Column();
$column->setName($columnName);
Expand Down
5 changes: 2 additions & 3 deletions src/Db/Action/ChangeColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Migrations\Db\Action;

use Migrations\Db\Literal;
use Migrations\Db\Table\Column;
use Migrations\Db\Table\TableMetadata;

Expand Down Expand Up @@ -53,11 +52,11 @@ public function __construct(TableMetadata $table, string $columnName, Column $co
*
* @param \Migrations\Db\Table\TableMetadata $table The table to alter
* @param string $columnName The name of the column to change
* @param string|\Migrations\Db\Literal $type The type of the column
* @param string $type The type of the column
* @param array<string, mixed> $options Additional options for the column
* @return self
*/
public static function build(TableMetadata $table, string $columnName, string|Literal $type, array $options = []): self
public static function build(TableMetadata $table, string $columnName, string $type, array $options = []): self
{
$column = new Column();
$column->setName($columnName);
Expand Down
2 changes: 1 addition & 1 deletion src/Db/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public function getAdapterType(): string
*/
public function isValidColumnType(Column $column): bool
{
return $column->getType() instanceof Literal || in_array($column->getType(), $this->getColumnTypes(), true);
return in_array($column->getType(), $this->getColumnTypes(), true);
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,10 +642,7 @@ static function ($value) {
$extra = ' ' . implode(' ', $extras);

if (($row['Default'] !== null)) {
$columnType = $targetColumn->getType();
// Column::getType() can return string|Literal, but getDefaultValueDefinition expects string|null
$columnTypeName = is_string($columnType) ? $columnType : null;
$extra .= $this->getDefaultValueDefinition($row['Default'], $columnTypeName);
$extra .= $this->getDefaultValueDefinition($row['Default'], $targetColumn->getType());
}
$definition = $row['Type'] . ' ' . $null . $extra . $comment;

Expand Down
10 changes: 4 additions & 6 deletions src/Db/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,16 @@ public function addPrimaryKey(string|array $columns)
* Valid options can be: limit, default, null, precision or scale.
*
* @param string|\Migrations\Db\Table\Column $columnName Column Name
* @param string|\Migrations\Db\Literal|null $type Column Type
* @param string|null $type Column Type
* @param array<string, mixed> $options Column Options
* @throws \InvalidArgumentException
* @return $this
*/
public function addColumn(string|Column $columnName, string|Literal|null $type = null, array $options = [])
public function addColumn(string|Column $columnName, ?string $type = null, array $options = [])
{
assert($columnName instanceof Column || $type !== null);
if ($columnName instanceof Column) {
$action = new AddColumn($this->table, $columnName);
} elseif ($type instanceof Literal) {
$action = AddColumn::build($this->table, $columnName, $type, $options);
} else {
$action = new AddColumn($this->table, $this->getAdapter()->getColumnForType($columnName, $type, $options));
}
Expand Down Expand Up @@ -388,11 +386,11 @@ public function renameColumn(string $oldName, string $newName)
* Change a table column type.
*
* @param string $columnName Column Name
* @param string|\Migrations\Db\Table\Column|\Migrations\Db\Literal $newColumnType New Column Type
* @param string|\Migrations\Db\Table\Column $newColumnType New Column Type
* @param array<string, mixed> $options Options
* @return $this
*/
public function changeColumn(string $columnName, string|Column|Literal $newColumnType, array $options = [])
public function changeColumn(string $columnName, string|Column $newColumnType, array $options = [])
{
if ($newColumnType instanceof Column) {
$action = new ChangeColumn($this->table, $columnName, $newColumnType);
Expand Down
Loading
Loading