Skip to content
Draft
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
2 changes: 1 addition & 1 deletion src/Phinx/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ protected function getColumnSqlDefinition(Column $column): string
}
if ($column->getPrecision() && $column->getScale() !== null) {
$def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')';
} elseif (isset($sqlType['limit'])) {
} elseif (($column->getLimit() !== null || !$column->hasLimitSet()) && isset($sqlType['limit'])) {
$def .= '(' . $sqlType['limit'] . ')';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Phinx/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ protected function getColumnSqlDefinition(Column $column): string
self::PHINX_TYPE_BINARY,
], true)
) {
if ($column->getLimit() || isset($sqlType['limit'])) {
if ($column->getLimit() || (!$column->hasLimitSet() && isset($sqlType['limit']))) {
$buffer[] = sprintf('(%s)', $column->getLimit() ?: $sqlType['limit']);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Phinx/Db/Adapter/SQLiteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ protected function getColumnSqlDefinition(Column $column): string
$def = strtoupper($sqlType['name']);

$limitable = in_array(strtoupper($sqlType['name']), $this->definitionsWithLimits, true);
if (($column->getLimit() || isset($sqlType['limit'])) && $limitable) {
if (($column->getLimit() || (!$column->hasLimitSet() && isset($sqlType['limit']))) && $limitable) {
$def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')';
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Phinx/Db/Adapter/SqlServerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ protected function getColumnSqlDefinition(Column $column, bool $create = true):
$column->getPrecision() ?: $sqlType['precision'],
$column->getScale() ?: $sqlType['scale'],
);
} elseif (!in_array($sqlType['name'], $noLimits) && ($column->getLimit() || isset($sqlType['limit']))) {
} elseif (!in_array($sqlType['name'], $noLimits) && ($column->getLimit() || (!$column->hasLimitSet() && isset($sqlType['limit'])))) {
$buffer[] = sprintf('(%s)', $column->getLimit() ?: $sqlType['limit']);
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/Phinx/Db/Table/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class Column
*/
protected ?int $limit = null;

/**
* @var bool
*/
protected bool $limitSet = false;

/**
* @var bool
*/
Expand Down Expand Up @@ -229,6 +234,7 @@ public function getType(): string|Literal
public function setLimit(?int $limit)
{
$this->limit = $limit;
$this->limitSet = true;

return $this;
}
Expand All @@ -243,6 +249,11 @@ public function getLimit(): ?int
return $this->limit;
}

public function hasLimitSet(): bool
{
return $this->limitSet;
}

/**
* Sets whether the column allows nulls.
*
Expand Down
Loading