From 6f00178acdc43b1a93931424f782973ab35b94b1 Mon Sep 17 00:00:00 2001 From: Sasa Blagojevic Date: Sat, 12 Aug 2023 10:44:06 +0200 Subject: [PATCH 1/4] Use platform options instead of deprecated custom schema options --- src/Event/ORMSchemaEventSubscriber.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Event/ORMSchemaEventSubscriber.php b/src/Event/ORMSchemaEventSubscriber.php index 2eee6be2..fb51a38f 100644 --- a/src/Event/ORMSchemaEventSubscriber.php +++ b/src/Event/ORMSchemaEventSubscriber.php @@ -32,12 +32,12 @@ public function postGenerateSchemaTable(GenerateSchemaTableEventArgs $args): voi } /** @var array{geometry_type?: string|null, srid?: int|string|null} $options */ - $options = $column->getCustomSchemaOptions(); + $options = $column->getPlatformOptions(); $normalized = $type->getNormalizedPostGISColumnOptions($options); foreach ($normalized as $name => $value) { - $column->setCustomSchemaOption($name, $value); + $column->setPlatformOption($name, $value); } } } From de3fa917b4c0d66b62eec50d112aa1ca057f6b2c Mon Sep 17 00:00:00 2001 From: Sasa Blagojevic Date: Sat, 12 Aug 2023 11:21:08 +0200 Subject: [PATCH 2/4] Add missing argument in test case --- tests/Event/DBALSchemaEventSubscriberTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Event/DBALSchemaEventSubscriberTest.php b/tests/Event/DBALSchemaEventSubscriberTest.php index a1cbaa7b..5a626e14 100644 --- a/tests/Event/DBALSchemaEventSubscriberTest.php +++ b/tests/Event/DBALSchemaEventSubscriberTest.php @@ -330,7 +330,7 @@ public function testGetCreateTableSqlSkipsAlreadyAddedTable(): void { $schema = new Schema([], [], $this->sm->createSchemaConfig()); - $this->_getMessengerConnection()->configureSchema($schema, $this->_getConnection()); + $this->_getMessengerConnection()->configureSchema($schema, $this->_getConnection(), static fn () => false); $sql = $this->_getConnection()->getDatabasePlatform()->getCreateTableSQL($schema->getTable('messenger_messages')); From 3ae71a8b694aff2228254fe2d503d9bdb8f1b7b3 Mon Sep 17 00:00:00 2001 From: Sasa Blagojevic Date: Sat, 12 Aug 2023 12:24:42 +0200 Subject: [PATCH 3/4] Replace all calls to deprecated custom schema option methods --- psalm.xml | 3 - src/Event/DBALSchemaEventSubscriber.php | 8 +-- tests/Event/DBALSchemaEventSubscriberTest.php | 60 +++++++++---------- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/psalm.xml b/psalm.xml index 6a4f168d..40b8fc34 100644 --- a/psalm.xml +++ b/psalm.xml @@ -28,9 +28,6 @@ - - - diff --git a/src/Event/DBALSchemaEventSubscriber.php b/src/Event/DBALSchemaEventSubscriber.php index db9e1dd3..7e8b9489 100644 --- a/src/Event/DBALSchemaEventSubscriber.php +++ b/src/Event/DBALSchemaEventSubscriber.php @@ -152,7 +152,7 @@ public function onSchemaAlterTableChangeColumn(SchemaAlterTableChangeColumnEvent } if ($columnDiff->hasChanged('geometry_type')) { - throw new RuntimeException('The geometry_type of a spatial column cannot be changed (Requested changing type from "' . strtoupper((string) ($columnDiff->fromColumn?->getCustomSchemaOption('geometry_type') ?? 'N/A')) . '" to "' . strtoupper((string) $column->getCustomSchemaOption('geometry_type')) . '" for column "' . $column->getName() . '" in table "' . $table->getName() . '")'); + throw new RuntimeException('The geometry_type of a spatial column cannot be changed (Requested changing type from "' . strtoupper((string) ($columnDiff->fromColumn?->getPlatformOption('geometry_type') ?? 'N/A')) . '" to "' . strtoupper((string) $column->getPlatformOption('geometry_type')) . '" for column "' . $column->getName() . '" in table "' . $table->getName() . '")'); } if ($columnDiff->hasChanged('srid')) { @@ -160,7 +160,7 @@ public function onSchemaAlterTableChangeColumn(SchemaAlterTableChangeColumnEvent "SELECT UpdateGeometrySRID('%s', '%s', %d)", $table->getName(), $column->getName(), - (int) $column->getCustomSchemaOption('srid') + (int) $column->getPlatformOption('srid') )); } } @@ -201,8 +201,8 @@ public function onSchemaColumnDefinition(SchemaColumnDefinitionEventArgs $args): $column = new Column($tableColumn['field'], PostGISType::getType($tableColumn['type']), $options); $column - ->setCustomSchemaOption('geometry_type', $info['type']) - ->setCustomSchemaOption('srid', $info['srid']) + ->setPlatformOption('geometry_type', $info['type']) + ->setPlatformOption('srid', $info['srid']) ; $args diff --git a/tests/Event/DBALSchemaEventSubscriberTest.php b/tests/Event/DBALSchemaEventSubscriberTest.php index 5a626e14..84762828 100644 --- a/tests/Event/DBALSchemaEventSubscriberTest.php +++ b/tests/Event/DBALSchemaEventSubscriberTest.php @@ -47,68 +47,68 @@ private function createTableSchema(): Table $table->addColumn('tsvector', 'tsvector', ['notnull' => true]); $table->addColumn('geometry', 'geometry', ['notnull' => true]) - ->setCustomSchemaOptions([ + ->setPlatformOptions([ 'geometry_type' => 'GEOMETRY', 'srid' => 0, ]); $table->addColumn('point', 'geometry', ['notnull' => true]) - ->setCustomSchemaOptions([ + ->setPlatformOptions([ 'geometry_type' => 'POINT', 'srid' => 0, ]) ->setComment('This is a comment for column point'); $table->addColumn('point_2d', 'geometry', ['notnull' => true]) - ->setCustomSchemaOptions([ + ->setPlatformOptions([ 'geometry_type' => 'POINT', 'srid' => 3785, ]); $table->addColumn('point_3dz', 'geometry', ['notnull' => true]) - ->setCustomSchemaOptions([ + ->setPlatformOptions([ 'geometry_type' => 'POINTZ', 'srid' => 3785, ]); $table->addColumn('point_3dm', 'geometry', ['notnull' => true]) - ->setCustomSchemaOptions([ + ->setPlatformOptions([ 'geometry_type' => 'POINTM', 'srid' => 3785, ]); $table->addColumn('point_4d', 'geometry', ['notnull' => true]) - ->setCustomSchemaOptions([ + ->setPlatformOptions([ 'geometry_type' => 'POINTZM', 'srid' => 3785, ]); $table->addColumn('point_2d_nullable', 'geometry', ['notnull' => false]) - ->setCustomSchemaOptions([ + ->setPlatformOptions([ 'geometry_type' => 'POINT', 'srid' => 3785, ]); $table->addColumn('point_2d_nosrid', 'geometry', ['notnull' => true]) - ->setCustomSchemaOptions([ + ->setPlatformOptions([ 'geometry_type' => 'POINT', 'srid' => 0, ]); $table->addColumn('geography', 'geography', ['notnull' => true]) - ->setCustomSchemaOptions([ + ->setPlatformOptions([ 'geometry_type' => 'GEOMETRY', 'srid' => 4326, ]); $table->addColumn('point_geography_2d', 'geography', ['notnull' => true]) - ->setCustomSchemaOptions([ + ->setPlatformOptions([ 'geometry_type' => 'POINT', 'srid' => 4326, ]); $table->addColumn('point_geography_2d_srid', 'geography', ['notnull' => true]) - ->setCustomSchemaOptions([ + ->setPlatformOptions([ 'geometry_type' => 'POINT', 'srid' => 4326, ]); @@ -145,8 +145,8 @@ public function testListTableColumns(): void $this->assertNull($columns['point']->getDefault()); $this->assertIsArray($columns['point']->getPlatformOptions()); - $this->assertEquals('POINT', $columns['point']->getCustomSchemaOption('geometry_type')); - $this->assertEquals(0, $columns['point']->getCustomSchemaOption('srid')); + $this->assertEquals('POINT', $columns['point']->getPlatformOption('geometry_type')); + $this->assertEquals(0, $columns['point']->getPlatformOption('srid')); // --- @@ -158,8 +158,8 @@ public function testListTableColumns(): void $this->assertNull($columns['point_2d']->getDefault()); $this->assertIsArray($columns['point_2d']->getPlatformOptions()); - $this->assertEquals('POINT', $columns['point_2d']->getCustomSchemaOption('geometry_type')); - $this->assertEquals(3785, $columns['point_2d']->getCustomSchemaOption('srid')); + $this->assertEquals('POINT', $columns['point_2d']->getPlatformOption('geometry_type')); + $this->assertEquals(3785, $columns['point_2d']->getPlatformOption('srid')); // --- @@ -171,8 +171,8 @@ public function testListTableColumns(): void $this->assertNull($columns['point_3dz']->getDefault()); $this->assertIsArray($columns['point_3dz']->getPlatformOptions()); - $this->assertEquals('POINTZ', $columns['point_3dz']->getCustomSchemaOption('geometry_type')); - $this->assertEquals(3785, $columns['point_3dz']->getCustomSchemaOption('srid')); + $this->assertEquals('POINTZ', $columns['point_3dz']->getPlatformOption('geometry_type')); + $this->assertEquals(3785, $columns['point_3dz']->getPlatformOption('srid')); // --- @@ -184,8 +184,8 @@ public function testListTableColumns(): void $this->assertNull($columns['point_3dm']->getDefault()); $this->assertIsArray($columns['point_3dm']->getPlatformOptions()); - $this->assertEquals('POINTM', $columns['point_3dm']->getCustomSchemaOption('geometry_type')); - $this->assertEquals(3785, $columns['point_3dm']->getCustomSchemaOption('srid')); + $this->assertEquals('POINTM', $columns['point_3dm']->getPlatformOption('geometry_type')); + $this->assertEquals(3785, $columns['point_3dm']->getPlatformOption('srid')); // --- @@ -197,8 +197,8 @@ public function testListTableColumns(): void $this->assertNull($columns['point_4d']->getDefault()); $this->assertIsArray($columns['point_4d']->getPlatformOptions()); - $this->assertEquals('POINTZM', $columns['point_4d']->getCustomSchemaOption('geometry_type')); - $this->assertEquals(3785, $columns['point_4d']->getCustomSchemaOption('srid')); + $this->assertEquals('POINTZM', $columns['point_4d']->getPlatformOption('geometry_type')); + $this->assertEquals(3785, $columns['point_4d']->getPlatformOption('srid')); // --- @@ -210,8 +210,8 @@ public function testListTableColumns(): void // $this->assertEquals('NULL::geometry', $columns['point_2d_nullable']->getDefault()); $this->assertIsArray($columns['point_2d_nullable']->getPlatformOptions()); - $this->assertEquals('POINT', $columns['point_2d_nullable']->getCustomSchemaOption('geometry_type')); - $this->assertEquals(3785, $columns['point_2d_nullable']->getCustomSchemaOption('srid')); + $this->assertEquals('POINT', $columns['point_2d_nullable']->getPlatformOption('geometry_type')); + $this->assertEquals(3785, $columns['point_2d_nullable']->getPlatformOption('srid')); // --- @@ -223,8 +223,8 @@ public function testListTableColumns(): void $this->assertNull($columns['point_2d_nosrid']->getDefault()); $this->assertIsArray($columns['point_2d_nosrid']->getPlatformOptions()); - $this->assertEquals('POINT', $columns['point_2d_nosrid']->getCustomSchemaOption('geometry_type')); - $this->assertEquals(0, $columns['point_2d_nosrid']->getCustomSchemaOption('srid')); + $this->assertEquals('POINT', $columns['point_2d_nosrid']->getPlatformOption('geometry_type')); + $this->assertEquals(0, $columns['point_2d_nosrid']->getPlatformOption('srid')); // --- @@ -236,8 +236,8 @@ public function testListTableColumns(): void $this->assertNull($columns['point_geography_2d']->getDefault()); $this->assertIsArray($columns['point_geography_2d']->getPlatformOptions()); - $this->assertEquals('POINT', $columns['point_geography_2d']->getCustomSchemaOption('geometry_type')); - $this->assertEquals(4326, $columns['point_geography_2d']->getCustomSchemaOption('srid')); + $this->assertEquals('POINT', $columns['point_geography_2d']->getPlatformOption('geometry_type')); + $this->assertEquals(4326, $columns['point_geography_2d']->getPlatformOption('srid')); // --- @@ -249,8 +249,8 @@ public function testListTableColumns(): void $this->assertNull($columns['point_geography_2d_srid']->getDefault()); $this->assertIsArray($columns['point_geography_2d_srid']->getPlatformOptions()); - $this->assertEquals('POINT', $columns['point_geography_2d_srid']->getCustomSchemaOption('geometry_type')); - $this->assertEquals(4326, $columns['point_geography_2d_srid']->getCustomSchemaOption('srid')); + $this->assertEquals('POINT', $columns['point_geography_2d_srid']->getPlatformOption('geometry_type')); + $this->assertEquals(4326, $columns['point_geography_2d_srid']->getPlatformOption('srid')); } public function testDiffListTableColumns(): void @@ -368,7 +368,7 @@ public function testAlterTableScenario(): void $table = $this->sm->listTableDetails('points'); $this->assertFalse($table->hasColumn('point')); $this->assertTrue($table->hasColumn('linestring')); - $this->assertEquals(4326, $table->getColumn('point_3dm')->getCustomSchemaOption('srid')); + $this->assertEquals(4326, $table->getColumn('point_3dm')->getPlatformOption('srid')); $tableDiff = new TableDiff('points'); $tableDiff->fromTable = $table; From 7fa08bb03d46322aabd8d66c8e4b205b04bbbc0d Mon Sep 17 00:00:00 2001 From: Sasa Blagojevic Date: Sat, 12 Aug 2023 12:29:40 +0200 Subject: [PATCH 4/4] Update test setup --- tests/Event/DBALSchemaEventSubscriberTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Event/DBALSchemaEventSubscriberTest.php b/tests/Event/DBALSchemaEventSubscriberTest.php index 84762828..c91f2425 100644 --- a/tests/Event/DBALSchemaEventSubscriberTest.php +++ b/tests/Event/DBALSchemaEventSubscriberTest.php @@ -359,9 +359,9 @@ public function testAlterTableScenario(): void $tableDiff = new TableDiff('points'); $tableDiff->fromTable = $table; - $tableDiff->addedColumns['linestring'] = new Column('linestring', Type::getType('geometry'), ['customSchemaOptions' => ['geometry_type' => 'linestring', 'srid' => 3785]]); + $tableDiff->addedColumns['linestring'] = new Column('linestring', Type::getType('geometry'), ['platformOptions' => ['geometry_type' => 'linestring', 'srid' => 3785]]); $tableDiff->removedColumns['point'] = $table->getColumn('point'); - $tableDiff->changedColumns[] = new ColumnDiff('point_3dm', new Column('point_3dm', Type::getType('geometry'), ['customSchemaOptions' => ['srid' => 4326]]), ['srid'], $table->getColumn('point_3dm')); + $tableDiff->changedColumns[] = new ColumnDiff('point_3dm', new Column('point_3dm', Type::getType('geometry'), ['platformOptions' => ['srid' => 4326]]), ['srid'], $table->getColumn('point_3dm')); $this->sm->alterTable($tableDiff); @@ -431,7 +431,7 @@ public function testAlterTableThrowsExceptionForChangedSpatialType(): void $tableDiff = new TableDiff('points'); $tableDiff->fromTable = $table; - $tableDiff->changedColumns[] = new ColumnDiff('point_2d', new Column('point_2d', Type::getType('geometry'), ['customSchemaOptions' => ['geometry_type' => 'LINESTRING']]), ['geometry_type'], $table->getColumn('point_2d')); + $tableDiff->changedColumns[] = new ColumnDiff('point_2d', new Column('point_2d', Type::getType('geometry'), ['platformOptions' => ['geometry_type' => 'LINESTRING']]), ['geometry_type'], $table->getColumn('point_2d')); $this->sm->alterTable($tableDiff); }