Skip to content

Commit ba9cf5f

Browse files
committed
tweaks
1 parent b275ed7 commit ba9cf5f

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

src/Phinx/Db/Adapter/MysqlAdapter.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -956,10 +956,9 @@ public function getSqlType(Literal|string $type, ?int $limit = null): array
956956
{
957957
$type = (string)$type;
958958
switch ($type) {
959-
case static::PHINX_TYPE_DECIMAL:
960-
return ['name' => $type, 'precision' => 10, 'scale' => 0];
961959
case static::PHINX_TYPE_FLOAT:
962960
case static::PHINX_TYPE_DOUBLE:
961+
case static::PHINX_TYPE_DECIMAL:
963962
case static::PHINX_TYPE_DATE:
964963
case static::PHINX_TYPE_ENUM:
965964
case static::PHINX_TYPE_SET:
@@ -1356,12 +1355,8 @@ protected function getColumnSqlDefinition(Column $column): string
13561355
$sqlType = $this->getSqlType($column->getType(), $column->getLimit());
13571356
$def = strtoupper($sqlType['name']);
13581357
}
1359-
if ($column->getPrecision() || $column->getScale()) {
1360-
$def .= sprintf(
1361-
'(%s, %s)',
1362-
$column->getPrecision() ?: ($sqlType['precision'] ?? 10),
1363-
$column->getScale() ?: ($sqlType['scale'] ?? 0),
1364-
);
1358+
if ($column->getPrecision() && $column->getScale() !== null) {
1359+
$def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')';
13651360
} elseif (isset($sqlType['limit'])) {
13661361
$def .= '(' . $sqlType['limit'] . ')';
13671362
}

src/Phinx/Db/Adapter/SQLiteAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ protected function getColumnSqlDefinition(Column $column): string
18681868
$def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')';
18691869
}
18701870
}
1871-
if ($column->getPrecision() || $column->getScale()) {
1871+
if ($column->getPrecision() && $column->getScale() !== null) {
18721872
$def .= sprintf(
18731873
'(%s, %s)',
18741874
$column->getPrecision() ?: 10,

tests/Phinx/Db/Adapter/SqlServerAdapterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,15 +731,15 @@ public function testGetColumns($colName, $type, $options)
731731
$this->assertEquals($type, $columns[$colName]->getType());
732732

733733
if (isset($options['limit'])) {
734-
$this->assertEquals($options['limit'], $columns[1]->getLimit());
734+
$this->assertEquals($options['limit'], $columns[$colName]->getLimit());
735735
}
736736

737737
if (isset($options['precision'])) {
738-
$this->assertEquals($options['precision'], $columns[1]->getPrecision());
738+
$this->assertEquals($options['precision'], $columns[$colName]->getPrecision());
739739
}
740740

741741
if (isset($options['scale'])) {
742-
$this->assertEquals($options['scale'], $columns[1]->getScale());
742+
$this->assertEquals($options['scale'], $columns[$colName]->getScale());
743743
}
744744
}
745745

0 commit comments

Comments
 (0)