|
6 | 6 |
|
7 | 7 | use Doctrine\DBAL\Platforms\PostgreSQLPlatform; |
8 | 8 | use Doctrine\DBAL\Schema\Column; |
| 9 | +use Doctrine\DBAL\Schema\Index; |
| 10 | +use Doctrine\DBAL\Schema\Index\IndexType; |
9 | 11 | use Doctrine\DBAL\Schema\PrimaryKeyConstraint; |
10 | 12 | use Doctrine\DBAL\Schema\Table; |
11 | 13 | use Doctrine\DBAL\Tests\Functional\SpatialTestCase; |
@@ -344,4 +346,55 @@ public function testAlterTableAlterSpatialColumn(): void |
344 | 346 | self::assertSame('Polygon', $geog->getGeometryType()); |
345 | 347 | self::assertSame(4267, $geog->getSrid()); |
346 | 348 | } |
| 349 | + |
| 350 | + public function testSpatialIndex(): void |
| 351 | + { |
| 352 | + $index = Index::editor() |
| 353 | + ->setUnquotedName('spatial_idx') |
| 354 | + ->setType(IndexType::SPATIAL) |
| 355 | + ->setUnquotedColumnNames('location') |
| 356 | + ->create(); |
| 357 | + |
| 358 | + $table = Table::editor() |
| 359 | + ->setUnquotedName(self::TABLE_NAME) |
| 360 | + ->setColumns( |
| 361 | + Column::editor() |
| 362 | + ->setUnquotedName('id') |
| 363 | + ->setTypeName(Types::INTEGER) |
| 364 | + ->setAutoincrement(true) |
| 365 | + ->create(), |
| 366 | + Column::editor() |
| 367 | + ->setUnquotedName('location') |
| 368 | + ->setTypeName(Types::GEOMETRY) |
| 369 | + ->setGeometryType('POINT') |
| 370 | + ->setSrid(4326) |
| 371 | + ->create(), |
| 372 | + ) |
| 373 | + ->setPrimaryKeyConstraint( |
| 374 | + PrimaryKeyConstraint::editor() |
| 375 | + ->setUnquotedColumnNames('id') |
| 376 | + ->create(), |
| 377 | + ) |
| 378 | + ->setIndexes($index) |
| 379 | + ->create(); |
| 380 | + |
| 381 | + $schemaManager = $this->connection->createSchemaManager(); |
| 382 | + $schemaManager->createTable($table); |
| 383 | + |
| 384 | + $onlineTable = $schemaManager->introspectTableByUnquotedName(self::TABLE_NAME); |
| 385 | + |
| 386 | + // Verify the table structure is maintained |
| 387 | + self::assertTrue( |
| 388 | + $schemaManager->createComparator() |
| 389 | + ->compareTables($table, $onlineTable) |
| 390 | + ->isEmpty(), |
| 391 | + ); |
| 392 | + |
| 393 | + // Verify the spatial index exists |
| 394 | + self::assertTrue($onlineTable->hasIndex('spatial_idx')); |
| 395 | + |
| 396 | + // Verify the index type is SPATIAL |
| 397 | + $spatialIndex = $onlineTable->getIndex('spatial_idx'); |
| 398 | + self::assertSame(IndexType::SPATIAL, $spatialIndex->getType()); |
| 399 | + } |
347 | 400 | } |
0 commit comments