From 53941e4b9b01764a64e49ea646596f15bb8ebd6e Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 17 Nov 2025 17:44:25 -0500 Subject: [PATCH 1/2] Setting limit to null omits it from definition Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/MysqlAdapter.php | 4 ++-- src/Phinx/Db/Adapter/PostgresAdapter.php | 2 +- src/Phinx/Db/Adapter/SQLiteAdapter.php | 2 +- src/Phinx/Db/Adapter/SqlServerAdapter.php | 2 +- src/Phinx/Db/Table/Column.php | 11 +++++++++++ 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Phinx/Db/Adapter/MysqlAdapter.php b/src/Phinx/Db/Adapter/MysqlAdapter.php index 8a767a74b..4f731cba8 100644 --- a/src/Phinx/Db/Adapter/MysqlAdapter.php +++ b/src/Phinx/Db/Adapter/MysqlAdapter.php @@ -1364,8 +1364,8 @@ protected function getColumnSqlDefinition(Column $column): string } if ($column->getPrecision() && $column->getScale() !== null) { $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; - } elseif (isset($sqlType['limit'])) { - $def .= '(' . $sqlType['limit'] . ')'; + } elseif ($column->getLimit() || (!$column->hasLimitSet() && isset($sqlType['limit']))) { + $def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')'; } $values = $column->getValues(); diff --git a/src/Phinx/Db/Adapter/PostgresAdapter.php b/src/Phinx/Db/Adapter/PostgresAdapter.php index 9dc0fe431..fc0ac1eb5 100644 --- a/src/Phinx/Db/Adapter/PostgresAdapter.php +++ b/src/Phinx/Db/Adapter/PostgresAdapter.php @@ -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']); } } diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index fe622177f..fb635ac8a 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -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']) . ')'; } } diff --git a/src/Phinx/Db/Adapter/SqlServerAdapter.php b/src/Phinx/Db/Adapter/SqlServerAdapter.php index 6a36f81cd..a64044530 100644 --- a/src/Phinx/Db/Adapter/SqlServerAdapter.php +++ b/src/Phinx/Db/Adapter/SqlServerAdapter.php @@ -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']); } } diff --git a/src/Phinx/Db/Table/Column.php b/src/Phinx/Db/Table/Column.php index 3941f037e..21ac3379a 100644 --- a/src/Phinx/Db/Table/Column.php +++ b/src/Phinx/Db/Table/Column.php @@ -75,6 +75,11 @@ class Column */ protected ?int $limit = null; + /** + * @var bool + */ + protected bool $limitSet = false; + /** * @var bool */ @@ -229,6 +234,7 @@ public function getType(): string|Literal public function setLimit(?int $limit) { $this->limit = $limit; + $this->limitSet = true; return $this; } @@ -243,6 +249,11 @@ public function getLimit(): ?int return $this->limit; } + public function hasLimitSet(): bool + { + return $this->limitSet; + } + /** * Sets whether the column allows nulls. * From fa4bb4154ab57dd5531815713d20d4d739c629bd Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 17 Nov 2025 17:58:41 -0500 Subject: [PATCH 2/2] fix logic for mysql Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/MysqlAdapter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Phinx/Db/Adapter/MysqlAdapter.php b/src/Phinx/Db/Adapter/MysqlAdapter.php index 4f731cba8..ffe014c20 100644 --- a/src/Phinx/Db/Adapter/MysqlAdapter.php +++ b/src/Phinx/Db/Adapter/MysqlAdapter.php @@ -1364,8 +1364,8 @@ protected function getColumnSqlDefinition(Column $column): string } if ($column->getPrecision() && $column->getScale() !== null) { $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; - } elseif ($column->getLimit() || (!$column->hasLimitSet() && isset($sqlType['limit']))) { - $def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')'; + } elseif (($column->getLimit() !== null || !$column->hasLimitSet()) && isset($sqlType['limit'])) { + $def .= '(' . $sqlType['limit'] . ')'; } $values = $column->getValues();