|
7 | 7 | use Doctrine\DBAL\Platforms\AbstractPlatform;
|
8 | 8 | use Doctrine\DBAL\Platforms\PostgreSQL120Platform;
|
9 | 9 | use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
|
| 10 | +use Doctrine\DBAL\Schema\Exception\TableDoesNotExist; |
10 | 11 | use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
11 | 12 | use Doctrine\DBAL\Schema\Schema;
|
12 | 13 | use Doctrine\DBAL\Schema\Table;
|
@@ -598,6 +599,56 @@ public static function autoIncrementTypeMigrations(): iterable
|
598 | 599 | 'bigint->int' => ['bigint', 'integer', 'INT'],
|
599 | 600 | ];
|
600 | 601 | }
|
| 602 | + |
| 603 | + public function testPartitionTable(): void |
| 604 | + { |
| 605 | + $this->connection->executeStatement('DROP TABLE IF EXISTS partitioned_table'); |
| 606 | + $this->connection->executeStatement( |
| 607 | + 'CREATE TABLE partitioned_table (id INT) PARTITION BY LIST (id);', |
| 608 | + ); |
| 609 | + $this->connection->executeStatement('CREATE TABLE partition PARTITION OF partitioned_table FOR VALUES IN (1);'); |
| 610 | + try { |
| 611 | + $this->schemaManager->introspectTable('partition'); |
| 612 | + } catch (TableDoesNotExist $e) { |
| 613 | + } |
| 614 | + |
| 615 | + self::assertNotNull($e ?? null, 'Partition table should not be introspected'); |
| 616 | + |
| 617 | + $tableFrom = $this->schemaManager->introspectTable('partitioned_table'); |
| 618 | + |
| 619 | + $tableTo = $this->schemaManager->introspectTable('partitioned_table'); |
| 620 | + $tableTo->addColumn('foo', Types::INTEGER); |
| 621 | + |
| 622 | + $platform = $this->connection->getDatabasePlatform(); |
| 623 | + $diff = $this->schemaManager->createComparator()->compareTables($tableFrom, $tableTo); |
| 624 | + |
| 625 | + $sql = $platform->getAlterTableSQL($diff); |
| 626 | + self::assertSame(['ALTER TABLE partitioned_table ADD foo INT NOT NULL'], $sql); |
| 627 | + |
| 628 | + $this->schemaManager->alterTable($diff); |
| 629 | + |
| 630 | + $tableFinal = $this->schemaManager->introspectTable('partitioned_table'); |
| 631 | + self::assertTrue($tableFinal->hasColumn('id')); |
| 632 | + self::assertTrue($tableFinal->hasColumn('foo')); |
| 633 | + |
| 634 | + $partitionedTableCount = (int) ($this->connection->fetchOne( |
| 635 | + "select count(*) as count from pg_class where relname = 'partitioned_table' and relkind = 'p'", |
| 636 | + )); |
| 637 | + self::assertSame(1, $partitionedTableCount); |
| 638 | + |
| 639 | + $partitionsCount = (int) ($this->connection->fetchOne( |
| 640 | + <<<'SQL' |
| 641 | + select count(*) as count |
| 642 | + from pg_class parent |
| 643 | + inner join pg_inherits on pg_inherits.inhparent = parent.oid |
| 644 | + inner join pg_class child on pg_inherits.inhrelid = child.oid |
| 645 | + and child.relkind = 'r' |
| 646 | + and child.relname = 'partition' |
| 647 | + where parent.relname = 'partitioned_table' and parent.relkind = 'p'; |
| 648 | + SQL, |
| 649 | + )); |
| 650 | + self::assertSame(1, $partitionsCount); |
| 651 | + } |
601 | 652 | }
|
602 | 653 |
|
603 | 654 | class MoneyType extends Type
|
|
0 commit comments