From 55b2ee1eadd8a2d7e7f4ad12f92fb7b2d470eedd Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Sun, 26 Oct 2025 23:17:20 +0000 Subject: [PATCH 01/14] Improve precision and scale behavior across adapters --- src/Phinx/Db/Adapter/MysqlAdapter.php | 11 ++++++++--- src/Phinx/Db/Adapter/SqlServerAdapter.php | 5 +++-- tests/Phinx/Db/Adapter/MysqlAdapterTest.php | 18 ++---------------- tests/Phinx/Db/Adapter/PostgresAdapterTest.php | 13 +++++++++++++ .../Phinx/Db/Adapter/SqlServerAdapterTest.php | 13 +++++++++++++ 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/Phinx/Db/Adapter/MysqlAdapter.php b/src/Phinx/Db/Adapter/MysqlAdapter.php index 0dfbb2e37..1b4384e4b 100644 --- a/src/Phinx/Db/Adapter/MysqlAdapter.php +++ b/src/Phinx/Db/Adapter/MysqlAdapter.php @@ -956,9 +956,10 @@ public function getSqlType(Literal|string $type, ?int $limit = null): array { $type = (string)$type; switch ($type) { + case static::PHINX_TYPE_DECIMAL: + return ['name' => $type, 'precision' => 10, 'scale' => 0]; case static::PHINX_TYPE_FLOAT: case static::PHINX_TYPE_DOUBLE: - case static::PHINX_TYPE_DECIMAL: case static::PHINX_TYPE_DATE: case static::PHINX_TYPE_ENUM: case static::PHINX_TYPE_SET: @@ -1355,8 +1356,12 @@ protected function getColumnSqlDefinition(Column $column): string $sqlType = $this->getSqlType($column->getType(), $column->getLimit()); $def = strtoupper($sqlType['name']); } - if ($column->getPrecision() && $column->getScale() !== null) { - $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; + if ($column->getPrecision() || $column->getScale()) { + $def .= sprintf( + '(%s, %s)', + $column->getPrecision() ?: $sqlType['precision'], + $column->getScale() ?: $sqlType['scale'], + ); } elseif (isset($sqlType['limit'])) { $def .= '(' . $sqlType['limit'] . ')'; } diff --git a/src/Phinx/Db/Adapter/SqlServerAdapter.php b/src/Phinx/Db/Adapter/SqlServerAdapter.php index 37b4bfd5e..37d43d3b9 100644 --- a/src/Phinx/Db/Adapter/SqlServerAdapter.php +++ b/src/Phinx/Db/Adapter/SqlServerAdapter.php @@ -1063,8 +1063,9 @@ public function getSqlType(Literal|string $type, ?int $limit = null): array { $type = (string)$type; switch ($type) { - case static::PHINX_TYPE_FLOAT: case static::PHINX_TYPE_DECIMAL: + return ['name' => $type, 'precision' => 18, 'scale' => 0]; + case static::PHINX_TYPE_FLOAT: case static::PHINX_TYPE_DATETIME: case static::PHINX_TYPE_TIME: case static::PHINX_TYPE_DATE: @@ -1237,7 +1238,7 @@ protected function getColumnSqlDefinition(Column $column, bool $create = true): 'tinyint', 'smallint', ]; - if ($sqlType['name'] === static::PHINX_TYPE_DECIMAL && $column->getPrecision() && $column->getScale()) { + if ($sqlType['name'] === static::PHINX_TYPE_DECIMAL && ($column->getPrecision() || $column->getScale())) { $buffer[] = sprintf( '(%s, %s)', $column->getPrecision() ?: $sqlType['precision'], diff --git a/tests/Phinx/Db/Adapter/MysqlAdapterTest.php b/tests/Phinx/Db/Adapter/MysqlAdapterTest.php index ab98cc51f..1285af763 100644 --- a/tests/Phinx/Db/Adapter/MysqlAdapterTest.php +++ b/tests/Phinx/Db/Adapter/MysqlAdapterTest.php @@ -1389,8 +1389,9 @@ public function columnsProvider() ['column6', 'float', []], ['column7', 'decimal', []], ['decimal_precision_scale', 'decimal', ['precision' => 10, 'scale' => 2]], + ['decimal_precision_zero_scale', 'decimal', ['precision' => 15, 'scale' => 0]], ['decimal_limit', 'decimal', ['limit' => 10]], - ['decimal_precision', 'decimal', ['precision' => 10]], + ['decimal_precision', 'decimal', ['precision' => 15]], ['column8', 'datetime', []], ['column9', 'time', []], ['column10', 'timestamp', []], @@ -2727,21 +2728,6 @@ public function testCreateTableWithPrecisionCurrentTimestamp() $this->assertEqualsIgnoringCase('CURRENT_TIMESTAMP(3)', $colDef['COLUMN_DEFAULT']); } - public function testCreateTableWithZeroScale(): void - { - $this->adapter->connect(); - $table = new Table('test_table', ['id' => false], $this->adapter); - $table - ->addColumn('col_1', 'decimal', ['null' => false, 'precision' => 15, 'scale' => 0]) - ->create(); - - $columns = $table->getColumns(); - $this->assertCount(1, $columns); - $this->assertSame('col_1', $columns[0]->getName()); - $this->assertSame(15, $columns[0]->getPrecision()); - $this->assertSame(0, $columns[0]->getScale()); - } - public function pdoAttributeProvider() { return [ diff --git a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php index 46714f992..d1db27e39 100644 --- a/tests/Phinx/Db/Adapter/PostgresAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PostgresAdapterTest.php @@ -1258,6 +1258,7 @@ public function columnsProvider() ['column13', 'string', ['limit' => 10]], ['column16', 'interval', []], ['decimal_precision_scale', 'decimal', ['precision' => 10, 'scale' => 2]], + ['decimal_precision_zero_scale', 'decimal', ['precision' => 12, 'scale' => 0]], ['decimal_limit', 'decimal', ['limit' => 10]], ['decimal_precision', 'decimal', ['precision' => 10]], ]; @@ -1284,6 +1285,18 @@ public function testGetColumns($colName, $type, $options, $actualType = null) } else { $this->assertEquals(['name' => $actualType] + $options, $columns[1]->getType()); } + + if (isset($options['limit'])) { + $this->assertEquals($options['limit'], $columns[1]->getLimit()); + } + + if (isset($options['precision'])) { + $this->assertEquals($options['precision'], $columns[1]->getPrecision()); + } + + if (isset($options['scale'])) { + $this->assertEquals($options['scale'], $columns[1]->getScale()); + } } /** diff --git a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php index e442e1aaa..359ca4a36 100644 --- a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php @@ -709,6 +709,7 @@ public function columnsProvider() ['column13', 'tinyinteger', ['default' => 5]], ['column14', 'smallinteger', ['default' => 5]], ['decimal_precision_scale', 'decimal', ['precision' => 10, 'scale' => 2]], + ['decimal_precision_zero_scale', 'decimal', ['precision' => 10, 'scale' => 0]], ['decimal_limit', 'decimal', ['limit' => 10]], ['decimal_precision', 'decimal', ['precision' => 10]], ]; @@ -728,6 +729,18 @@ public function testGetColumns($colName, $type, $options) $this->assertCount(2, $columns); $this->assertEquals($colName, $columns[$colName]->getName()); $this->assertEquals($type, $columns[$colName]->getType()); + + if (isset($options['limit'])) { + $this->assertEquals($options['limit'], $columns[1]->getLimit()); + } + + if (isset($options['precision'])) { + $this->assertEquals($options['precision'], $columns[1]->getPrecision()); + } + + if (isset($options['scale'])) { + $this->assertEquals($options['scale'], $columns[1]->getScale()); + } } public function testAddIndex() From 521c29fbb97b975de9960928760a075e0ed0302e Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Sun, 26 Oct 2025 23:20:22 +0000 Subject: [PATCH 02/14] include sqlite --- src/Phinx/Db/Adapter/SQLiteAdapter.php | 8 ++++++-- tests/Phinx/Db/Adapter/SQLiteAdapterTest.php | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index f6f7759c2..e3a42e7aa 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -1868,8 +1868,12 @@ protected function getColumnSqlDefinition(Column $column): string $def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')'; } } - if ($column->getPrecision() && $column->getScale()) { - $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; + if ($column->getPrecision() || $column->getScale()) { + $def .= sprintf( + '(%s, %s)', + $column->getPrecision() ?: 10, + $column->getScale() ?: 0, + ); } $default = $column->getDefault(); diff --git a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php index 433e618c5..0b4814aa9 100644 --- a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php @@ -1319,6 +1319,9 @@ public function columnsProvider() ['column15', 'smallinteger', []], ['column15', 'integer', []], ['column23', 'json', []], + ['decimal_precision_scale', 'decimal', ['precision' => 10, 'scale' => 2]], + ['decimal_precision_zero_scale', 'decimal', ['precision' => 10, 'scale' => 0]], + ['decimal_precision', 'decimal', ['precision' => 10]], ]; } From 1b35f3c8535ec399d868dc0b8bccbca1e316aa99 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Sun, 26 Oct 2025 23:21:23 +0000 Subject: [PATCH 03/14] . --- 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 1b4384e4b..162f14a4b 100644 --- a/src/Phinx/Db/Adapter/MysqlAdapter.php +++ b/src/Phinx/Db/Adapter/MysqlAdapter.php @@ -1359,8 +1359,8 @@ protected function getColumnSqlDefinition(Column $column): string if ($column->getPrecision() || $column->getScale()) { $def .= sprintf( '(%s, %s)', - $column->getPrecision() ?: $sqlType['precision'], - $column->getScale() ?: $sqlType['scale'], + $column->getPrecision() ?: ($sqlType['precision'] ?? 10), + $column->getScale() ?: ($sqlType['scale'] ?? 0), ); } elseif (isset($sqlType['limit'])) { $def .= '(' . $sqlType['limit'] . ')'; From b275ed71565bd9ab9659328969baa2d9b2b081a2 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Sun, 26 Oct 2025 23:22:55 +0000 Subject: [PATCH 04/14] phpstan Signed-off-by: Matthew Peveler --- phpstan-baseline.neon | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b6fe2d324..275c70d17 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -5,8 +5,3 @@ parameters: count: 1 path: src/Phinx/Db/Adapter/MysqlAdapter.php - - - message: "#^Ternary operator condition is always true\\.$#" - count: 2 - path: src/Phinx/Db/Adapter/SqlServerAdapter.php - From ba9cf5f20604f2998439399cadf22a9b89f32dc4 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 27 Oct 2025 00:04:45 +0000 Subject: [PATCH 05/14] tweaks --- src/Phinx/Db/Adapter/MysqlAdapter.php | 11 +++-------- src/Phinx/Db/Adapter/SQLiteAdapter.php | 2 +- tests/Phinx/Db/Adapter/SqlServerAdapterTest.php | 6 +++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Phinx/Db/Adapter/MysqlAdapter.php b/src/Phinx/Db/Adapter/MysqlAdapter.php index 162f14a4b..0dfbb2e37 100644 --- a/src/Phinx/Db/Adapter/MysqlAdapter.php +++ b/src/Phinx/Db/Adapter/MysqlAdapter.php @@ -956,10 +956,9 @@ public function getSqlType(Literal|string $type, ?int $limit = null): array { $type = (string)$type; switch ($type) { - case static::PHINX_TYPE_DECIMAL: - return ['name' => $type, 'precision' => 10, 'scale' => 0]; case static::PHINX_TYPE_FLOAT: case static::PHINX_TYPE_DOUBLE: + case static::PHINX_TYPE_DECIMAL: case static::PHINX_TYPE_DATE: case static::PHINX_TYPE_ENUM: case static::PHINX_TYPE_SET: @@ -1356,12 +1355,8 @@ protected function getColumnSqlDefinition(Column $column): string $sqlType = $this->getSqlType($column->getType(), $column->getLimit()); $def = strtoupper($sqlType['name']); } - if ($column->getPrecision() || $column->getScale()) { - $def .= sprintf( - '(%s, %s)', - $column->getPrecision() ?: ($sqlType['precision'] ?? 10), - $column->getScale() ?: ($sqlType['scale'] ?? 0), - ); + if ($column->getPrecision() && $column->getScale() !== null) { + $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } elseif (isset($sqlType['limit'])) { $def .= '(' . $sqlType['limit'] . ')'; } diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index e3a42e7aa..98e8cf454 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -1868,7 +1868,7 @@ protected function getColumnSqlDefinition(Column $column): string $def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')'; } } - if ($column->getPrecision() || $column->getScale()) { + if ($column->getPrecision() && $column->getScale() !== null) { $def .= sprintf( '(%s, %s)', $column->getPrecision() ?: 10, diff --git a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php index 359ca4a36..a69fc96a1 100644 --- a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php @@ -731,15 +731,15 @@ public function testGetColumns($colName, $type, $options) $this->assertEquals($type, $columns[$colName]->getType()); if (isset($options['limit'])) { - $this->assertEquals($options['limit'], $columns[1]->getLimit()); + $this->assertEquals($options['limit'], $columns[$colName]->getLimit()); } if (isset($options['precision'])) { - $this->assertEquals($options['precision'], $columns[1]->getPrecision()); + $this->assertEquals($options['precision'], $columns[$colName]->getPrecision()); } if (isset($options['scale'])) { - $this->assertEquals($options['scale'], $columns[1]->getScale()); + $this->assertEquals($options['scale'], $columns[$colName]->getScale()); } } From be4e685117c813f66e9b56dc8aa2ac575f0d058f Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 27 Oct 2025 00:08:53 +0000 Subject: [PATCH 06/14] revert mysql test change --- tests/Phinx/Db/Adapter/MysqlAdapterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Phinx/Db/Adapter/MysqlAdapterTest.php b/tests/Phinx/Db/Adapter/MysqlAdapterTest.php index 1285af763..1b6ec3d47 100644 --- a/tests/Phinx/Db/Adapter/MysqlAdapterTest.php +++ b/tests/Phinx/Db/Adapter/MysqlAdapterTest.php @@ -1391,7 +1391,7 @@ public function columnsProvider() ['decimal_precision_scale', 'decimal', ['precision' => 10, 'scale' => 2]], ['decimal_precision_zero_scale', 'decimal', ['precision' => 15, 'scale' => 0]], ['decimal_limit', 'decimal', ['limit' => 10]], - ['decimal_precision', 'decimal', ['precision' => 15]], + ['decimal_precision', 'decimal', ['precision' => 10]], ['column8', 'datetime', []], ['column9', 'time', []], ['column10', 'timestamp', []], From 91edc2fcc0becec221b9b7e72ceb6d54b22e5135 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 27 Oct 2025 00:10:48 +0000 Subject: [PATCH 07/14] add back baseline Signed-off-by: Matthew Peveler --- phpstan-baseline.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 275c70d17..dc18cb10c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,10 @@ parameters: ignoreErrors: + - + message: "#^Ternary operator condition is always true\\.$#" + count: 2 + path: src/Phinx/Db/Adapter/SqlServerAdapter.php + - message: "#^Expression on left side of \\?\\? is not nullable\\.$#" count: 1 From 2140ead146d60075546441635765f2727907ad38 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 27 Oct 2025 00:11:40 +0000 Subject: [PATCH 08/14] revert change Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/SQLiteAdapter.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Phinx/Db/Adapter/SQLiteAdapter.php b/src/Phinx/Db/Adapter/SQLiteAdapter.php index 98e8cf454..fe622177f 100644 --- a/src/Phinx/Db/Adapter/SQLiteAdapter.php +++ b/src/Phinx/Db/Adapter/SQLiteAdapter.php @@ -1869,11 +1869,7 @@ protected function getColumnSqlDefinition(Column $column): string } } if ($column->getPrecision() && $column->getScale() !== null) { - $def .= sprintf( - '(%s, %s)', - $column->getPrecision() ?: 10, - $column->getScale() ?: 0, - ); + $def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')'; } $default = $column->getDefault(); From c639dd248147dccaa706c443b9cf1f4a93bd88b7 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 27 Oct 2025 00:13:27 +0000 Subject: [PATCH 09/14] revert Signed-off-by: Matthew Peveler --- phpstan-baseline.neon | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index dc18cb10c..b6fe2d324 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,12 +1,12 @@ parameters: ignoreErrors: - - - message: "#^Ternary operator condition is always true\\.$#" - count: 2 - path: src/Phinx/Db/Adapter/SqlServerAdapter.php - - message: "#^Expression on left side of \\?\\? is not nullable\\.$#" count: 1 path: src/Phinx/Db/Adapter/MysqlAdapter.php + - + message: "#^Ternary operator condition is always true\\.$#" + count: 2 + path: src/Phinx/Db/Adapter/SqlServerAdapter.php + From bc94ada9baa6ea5d6b05b9084ee4b7e893c4ade7 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 27 Oct 2025 00:41:30 +0000 Subject: [PATCH 10/14] wip Signed-off-by: Matthew Peveler --- phpstan-baseline.neon | 6 ------ src/Phinx/Db/Adapter/SqlServerAdapter.php | 5 +++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b6fe2d324..e94c74dde 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4,9 +4,3 @@ parameters: message: "#^Expression on left side of \\?\\? is not nullable\\.$#" count: 1 path: src/Phinx/Db/Adapter/MysqlAdapter.php - - - - message: "#^Ternary operator condition is always true\\.$#" - count: 2 - path: src/Phinx/Db/Adapter/SqlServerAdapter.php - diff --git a/src/Phinx/Db/Adapter/SqlServerAdapter.php b/src/Phinx/Db/Adapter/SqlServerAdapter.php index 37d43d3b9..06fb6f180 100644 --- a/src/Phinx/Db/Adapter/SqlServerAdapter.php +++ b/src/Phinx/Db/Adapter/SqlServerAdapter.php @@ -476,12 +476,17 @@ public function getColumns(string $tableName): array ->setNull($columnInfo['null'] !== 'NO') ->setDefault($this->parseDefault($columnInfo['default'])) ->setIdentity($columnInfo['identity'] === '1') + ->setScale($columnInfo['scale']) ->setComment($this->getColumnComment($columnInfo['table_name'], $columnInfo['name'])); if (!empty($columnInfo['char_length'])) { $column->setLimit((int)$columnInfo['char_length']); } + if ($type === self::PHINX_TYPE_DECIMAL) { + $column->setPrecision($columnInfo['numeric_precision']); + } + $columns[$columnInfo['name']] = $column; } From 3b71eddef3b48b3588de2c1fc05019b52dc41637 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 27 Oct 2025 00:47:22 +0000 Subject: [PATCH 11/14] cast to int for scale Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/SqlServerAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Phinx/Db/Adapter/SqlServerAdapter.php b/src/Phinx/Db/Adapter/SqlServerAdapter.php index 06fb6f180..18dde71ef 100644 --- a/src/Phinx/Db/Adapter/SqlServerAdapter.php +++ b/src/Phinx/Db/Adapter/SqlServerAdapter.php @@ -476,7 +476,7 @@ public function getColumns(string $tableName): array ->setNull($columnInfo['null'] !== 'NO') ->setDefault($this->parseDefault($columnInfo['default'])) ->setIdentity($columnInfo['identity'] === '1') - ->setScale($columnInfo['scale']) + ->setScale($columnInfo['scale'] ? (int)$columnInfo['scale'] : null) ->setComment($this->getColumnComment($columnInfo['table_name'], $columnInfo['name'])); if (!empty($columnInfo['char_length'])) { From c55a54fa37b4e4aedb2db3f6509efb8d04c9a81b Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 27 Oct 2025 15:38:19 +0000 Subject: [PATCH 12/14] Fix setting precision for sqlserver Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/SqlServerAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Phinx/Db/Adapter/SqlServerAdapter.php b/src/Phinx/Db/Adapter/SqlServerAdapter.php index 18dde71ef..d7c395a24 100644 --- a/src/Phinx/Db/Adapter/SqlServerAdapter.php +++ b/src/Phinx/Db/Adapter/SqlServerAdapter.php @@ -484,7 +484,7 @@ public function getColumns(string $tableName): array } if ($type === self::PHINX_TYPE_DECIMAL) { - $column->setPrecision($columnInfo['numeric_precision']); + $column->setPrecision($columnInfo['precision']); } $columns[$columnInfo['name']] = $column; From e38444c624741f7d3aa92a7e8cd72310d2efff96 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 27 Oct 2025 16:42:10 +0000 Subject: [PATCH 13/14] cast to int Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/SqlServerAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Phinx/Db/Adapter/SqlServerAdapter.php b/src/Phinx/Db/Adapter/SqlServerAdapter.php index d7c395a24..28a90f1f0 100644 --- a/src/Phinx/Db/Adapter/SqlServerAdapter.php +++ b/src/Phinx/Db/Adapter/SqlServerAdapter.php @@ -484,7 +484,7 @@ public function getColumns(string $tableName): array } if ($type === self::PHINX_TYPE_DECIMAL) { - $column->setPrecision($columnInfo['precision']); + $column->setPrecision((int)$columnInfo['precision']); } $columns[$columnInfo['name']] = $column; From 500b9e6b82cdcc152cba33c550c5651117d50337 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Mon, 27 Oct 2025 17:19:41 +0000 Subject: [PATCH 14/14] add testGetColumns test for sqlite similar to other adapters Signed-off-by: Matthew Peveler --- tests/Phinx/Db/Adapter/SQLiteAdapterTest.php | 33 ++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php index 0b4814aa9..e9665abe0 100644 --- a/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SQLiteAdapterTest.php @@ -1321,10 +1321,39 @@ public function columnsProvider() ['column23', 'json', []], ['decimal_precision_scale', 'decimal', ['precision' => 10, 'scale' => 2]], ['decimal_precision_zero_scale', 'decimal', ['precision' => 10, 'scale' => 0]], - ['decimal_precision', 'decimal', ['precision' => 10]], ]; } + /** + * @dataProvider columnsProvider + */ + public function testGetColumns($colName, $type, $options) + { + $table = new Table('t', [], $this->adapter); + $table->addColumn($colName, $type, $options)->save(); + + $columns = $this->adapter->getColumns('t'); + $this->assertCount(2, $columns); + $this->assertEquals($colName, $columns[1]->getName()); + $this->assertEquals($type, $columns[1]->getType()); + + if (isset($options['limit'])) { + $this->assertEquals($options['limit'], $columns[1]->getLimit()); + } + + if (isset($options['precision'])) { + $this->assertEquals($options['precision'], $columns[1]->getPrecision()); + } + + if (isset($options['scale'])) { + $this->assertEquals($options['scale'], $columns[1]->getScale()); + } + + if (isset($options['comment'])) { + $this->assertEquals($options['comment'], $columns[1]->getComment()); + } + } + public function testAddIndex() { $table = new Table('table1', [], $this->adapter); @@ -3169,7 +3198,7 @@ public function provideColumnNamesToCheck() * @covers \Phinx\Db\Adapter\SQLiteAdapter::getTableInfo * @covers \Phinx\Db\Adapter\SQLiteAdapter::getColumns */ - public function testGetColumns() + public function testGetMultipleColumns() { $conn = $this->adapter->getConnection(); $conn->exec('create table t(a integer, b text, c char(5), d integer(12,6), e integer not null, f integer null)');