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