Skip to content

Commit 9fb8416

Browse files
authored
Merge pull request #2214 from roblperry/fix_limit
Fix PostgresAdapter not returning limit for char and varchar
2 parents b2eef81 + 8163dbe commit 9fb8416

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

src/Phinx/Db/Adapter/PostgresAdapter.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,7 @@ public function getColumns(string $tableName): array
474474

475475
if (in_array($columnType, [static::PHINX_TYPE_TIME, static::PHINX_TYPE_DATETIME], true)) {
476476
$column->setPrecision($columnInfo['datetime_precision']);
477-
} elseif (
478-
!in_array($columnType, [
479-
self::PHINX_TYPE_SMALL_INTEGER,
480-
self::PHINX_TYPE_INTEGER,
481-
self::PHINX_TYPE_BIG_INTEGER,
482-
], true)
483-
) {
477+
} elseif ($columnType === self::PHINX_TYPE_DECIMAL) {
484478
$column->setPrecision($columnInfo['numeric_precision']);
485479
}
486480
$columns[] = $column;

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)