Skip to content

Commit d3a27aa

Browse files
committed
Check to see if numeric_precision is set, before calling setPrecision in PostgresAdapter, to avoid unsetting the limit previous set while getting columns from the database.
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.
1 parent b2eef81 commit d3a27aa

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

src/Phinx/Db/Adapter/PostgresAdapter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ public function getColumns(string $tableName): array
481481
self::PHINX_TYPE_BIG_INTEGER,
482482
], true)
483483
) {
484-
$column->setPrecision($columnInfo['numeric_precision']);
484+
if (isset($columnInfo['numeric_precision'])) {
485+
$column->setPrecision($columnInfo['numeric_precision']);
486+
}
485487
}
486488
$columns[] = $column;
487489
}

tests/Phinx/Db/Adapter/PostgresAdapterTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,25 @@ public function testAddColumnWithComment()
758758
);
759759
}
760760

761+
public function testAddStringWithLimit()
762+
{
763+
$table = new \Phinx\Db\Table('table1', [], $this->adapter);
764+
$table->save();
765+
$table->addColumn('string1', 'string', ['limit' => 10])
766+
->addColumn('char1', 'char', ['limit' => 20])
767+
->save();
768+
$columns = $this->adapter->getColumns('table1');
769+
foreach ($columns as $column) {
770+
if ($column->getName() === 'string1') {
771+
$this->assertEquals('10', $column->getLimit());
772+
}
773+
774+
if ($column->getName() === 'char1') {
775+
$this->assertEquals('20', $column->getLimit());
776+
}
777+
}
778+
}
779+
761780
public function testAddDecimalWithPrecisionAndScale()
762781
{
763782
$table = new \Phinx\Db\Table('table1', [], $this->adapter);

tests/Phinx/Migration/ManagerTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6147,26 +6147,16 @@ public function testMigrationWithCustomColumnTypes()
61476147
$this->assertArrayHasKey(3, $columns);
61486148
$this->assertArrayHasKey(4, $columns);
61496149

6150-
$limit = 15;
6151-
if ($adapter->getAdapterType() === 'pgsql') {
6152-
$limit = null;
6153-
}
6154-
61556150
$column = $columns[3];
61566151
$this->assertSame('phone_number', $column->getName());
61576152
$this->assertSame('string', $column->getType());
6158-
$this->assertSame($limit, $column->getLimit());
6153+
$this->assertSame(15, $column->getLimit());
61596154
$this->assertTrue($column->getNull());
61606155

6161-
$limit = 30;
6162-
if ($adapter->getAdapterType() === 'pgsql') {
6163-
$limit = null;
6164-
}
6165-
61666156
$column = $columns[4];
61676157
$this->assertSame('phone_number_ext', $column->getName());
61686158
$this->assertSame('string', $column->getType());
6169-
$this->assertSame($limit, $column->getLimit());
6159+
$this->assertSame(30, $column->getLimit());
61706160
$this->assertFalse($column->getNull());
61716161
}
61726162
}

0 commit comments

Comments
 (0)