|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Pfilsx\PostgreSQLDoctrine\DBAL\Platform; |
| 6 | + |
| 7 | +use Doctrine\DBAL\Connection; |
| 8 | +use Doctrine\DBAL\Exception; |
| 9 | +use Doctrine\DBAL\Platforms\PostgreSQLPlatform as BasePlatform; |
| 10 | +use Pfilsx\PostgreSQLDoctrine\DBAL\Schema\EnumTypeAsset; |
| 11 | +use Pfilsx\PostgreSQLDoctrine\DBAL\Schema\PostgreSQLSchemaManager; |
| 12 | +use Pfilsx\PostgreSQLDoctrine\DBAL\Type\EnumType; |
| 13 | + |
| 14 | +final class PostgreSQLPlatform extends BasePlatform |
| 15 | +{ |
| 16 | + public function createSchemaManager(Connection $connection): PostgreSQLSchemaManager |
| 17 | + { |
| 18 | + return new PostgreSQLSchemaManager($connection, $this); |
| 19 | + } |
| 20 | + |
| 21 | + public function getListEnumTypesSQL(): string |
| 22 | + { |
| 23 | + return 'SELECT pg_type.typname AS name, |
| 24 | + pg_enum.enumlabel AS label, |
| 25 | + pg_description.description AS comment |
| 26 | + FROM pg_type |
| 27 | + JOIN pg_enum ON pg_enum.enumtypid = pg_type.oid |
| 28 | + LEFT JOIN pg_description on pg_description.objoid = pg_type.oid |
| 29 | + ORDER BY pg_enum.enumsortorder'; |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @param EnumTypeAsset $type |
| 34 | + * @return string |
| 35 | + * @throws Exception\InvalidArgumentException |
| 36 | + */ |
| 37 | + public function getCreateTypeSql(EnumTypeAsset $type): string |
| 38 | + { |
| 39 | + return "CREATE TYPE {$type->getQuotedName($this)} AS ENUM(" . \implode(', ', $type->getQuotedLabels($this)) . ')'; |
| 40 | + } |
| 41 | + |
| 42 | + public function getCommentOnTypeSql(EnumTypeAsset $type): string |
| 43 | + { |
| 44 | + return "COMMENT ON TYPE {$type->getQuotedName($this)} IS '{$type->getEnumClass()}'"; |
| 45 | + } |
| 46 | + |
| 47 | + public function getAlterTypeSql(EnumTypeAsset $from, EnumTypeAsset $to): string |
| 48 | + { |
| 49 | + throw Exception::notSupported(__METHOD__); |
| 50 | + } |
| 51 | + |
| 52 | + public function getDropTypeSql(EnumTypeAsset $type): string |
| 53 | + { |
| 54 | + return "DROP TYPE {$type->getQuotedName($this)}"; |
| 55 | + } |
| 56 | + |
| 57 | + protected function initializeDoctrineTypeMappings() |
| 58 | + { |
| 59 | + parent::initializeDoctrineTypeMappings(); |
| 60 | + |
| 61 | + $this->doctrineTypeMapping[EnumType::NAME] = EnumType::NAME; |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments