Skip to content

Commit

Permalink
Modify getColumns to only read numeric_precision for columns of type …
Browse files Browse the repository at this point in the history
…PHINX_TYPE_DECIMAL

Added testAddStringWithLimit to PostgresAdapterTest to assure that limits are being properly set.
Updated ManagerTest->testMigrationWithCustomColumnTypes to no longer expect pgsql to return null for limit of custom columns.
  • Loading branch information
roblperry committed Sep 2, 2023
1 parent b2eef81 commit 8163dbe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
8 changes: 1 addition & 7 deletions src/Phinx/Db/Adapter/PostgresAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,7 @@ public function getColumns(string $tableName): array

if (in_array($columnType, [static::PHINX_TYPE_TIME, static::PHINX_TYPE_DATETIME], true)) {
$column->setPrecision($columnInfo['datetime_precision']);
} elseif (
!in_array($columnType, [
self::PHINX_TYPE_SMALL_INTEGER,
self::PHINX_TYPE_INTEGER,
self::PHINX_TYPE_BIG_INTEGER,
], true)
) {
} elseif ($columnType === self::PHINX_TYPE_DECIMAL) {

Check warning on line 477 in src/Phinx/Db/Adapter/PostgresAdapter.php

View check run for this annotation

Codecov / codecov/patch

src/Phinx/Db/Adapter/PostgresAdapter.php#L477

Added line #L477 was not covered by tests
$column->setPrecision($columnInfo['numeric_precision']);
}
$columns[] = $column;
Expand Down
19 changes: 19 additions & 0 deletions tests/Phinx/Db/Adapter/PostgresAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,25 @@ public function testAddColumnWithComment()
);
}

public function testAddStringWithLimit()
{
$table = new \Phinx\Db\Table('table1', [], $this->adapter);
$table->save();
$table->addColumn('string1', 'string', ['limit' => 10])
->addColumn('char1', 'char', ['limit' => 20])
->save();
$columns = $this->adapter->getColumns('table1');
foreach ($columns as $column) {
if ($column->getName() === 'string1') {
$this->assertEquals('10', $column->getLimit());
}

if ($column->getName() === 'char1') {
$this->assertEquals('20', $column->getLimit());
}
}
}

public function testAddDecimalWithPrecisionAndScale()
{
$table = new \Phinx\Db\Table('table1', [], $this->adapter);
Expand Down
14 changes: 2 additions & 12 deletions tests/Phinx/Migration/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6147,26 +6147,16 @@ public function testMigrationWithCustomColumnTypes()
$this->assertArrayHasKey(3, $columns);
$this->assertArrayHasKey(4, $columns);

$limit = 15;
if ($adapter->getAdapterType() === 'pgsql') {
$limit = null;
}

$column = $columns[3];
$this->assertSame('phone_number', $column->getName());
$this->assertSame('string', $column->getType());
$this->assertSame($limit, $column->getLimit());
$this->assertSame(15, $column->getLimit());
$this->assertTrue($column->getNull());

$limit = 30;
if ($adapter->getAdapterType() === 'pgsql') {
$limit = null;
}

$column = $columns[4];
$this->assertSame('phone_number_ext', $column->getName());
$this->assertSame('string', $column->getType());
$this->assertSame($limit, $column->getLimit());
$this->assertSame(30, $column->getLimit());
$this->assertFalse($column->getNull());
}
}

0 comments on commit 8163dbe

Please sign in to comment.