From 0a50d6851ee0e004729e0a249fd3341b5650c5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Tue, 13 Aug 2024 17:14:48 +0200 Subject: [PATCH] Ensure PostgreSQL field length change is executed again With #6280 quite some changes has been applied, which removed the code path to create alter sql statement if length of a field has changed. This change adds a general test for this case and reimplement the accidently removed code from the `PostgreSQLPlatform`. --- src/Platforms/PostgreSQLPlatform.php | 1 + .../Platform/AlterColumnLengthChangeTest.php | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/Functional/Platform/AlterColumnLengthChangeTest.php diff --git a/src/Platforms/PostgreSQLPlatform.php b/src/Platforms/PostgreSQLPlatform.php index c762772dee4..33ac34233ee 100644 --- a/src/Platforms/PostgreSQLPlatform.php +++ b/src/Platforms/PostgreSQLPlatform.php @@ -252,6 +252,7 @@ public function getAlterTableSQL(TableDiff $diff): array || $columnDiff->hasPrecisionChanged() || $columnDiff->hasScaleChanged() || $columnDiff->hasFixedChanged() + || $columnDiff->hasLengthChanged() ) { $type = $newColumn->getType(); diff --git a/tests/Functional/Platform/AlterColumnLengthChangeTest.php b/tests/Functional/Platform/AlterColumnLengthChangeTest.php new file mode 100644 index 00000000000..984aacc0f27 --- /dev/null +++ b/tests/Functional/Platform/AlterColumnLengthChangeTest.php @@ -0,0 +1,39 @@ +addColumn('c1', Types::STRING)->setLength(50); + + $this->dropAndCreateTable($table); + + $sm = $this->connection->createSchemaManager(); + $table = $sm->introspectTable('test_alter_length'); + $columns = $table->getColumns(); + self::assertCount(1, $columns); + self::assertSame(50, $columns[0]->getLength()); + + $table->getColumn('c1')->setLength(100); + + $diff = $sm->createComparator() + ->compareTables($sm->introspectTable('test_alter_length'), $table); + + $sm->alterTable($diff); + + $table = $sm->introspectTable('test_alter_length'); + $columns = $table->getColumns(); + + self::assertCount(1, $columns); + self::assertSame(100, $columns[0]->getLength()); + } +}