Skip to content

Commit e3045f8

Browse files
committed
fix enum update migration table/column quote
1 parent 47ed9f5 commit e3045f8

File tree

11 files changed

+44
-29
lines changed

11 files changed

+44
-29
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
PostgreSQL Doctrine
22
==============
33

4-
[![Latest Stable Version](http://poser.pugx.org/pfilsx/postgresql-doctrine/v)](https://packagist.org/packages/pfilsx/postgresql-doctrine)
5-
[![PHP Version Require](http://poser.pugx.org/pfilsx/postgresql-doctrine/require/php)](https://packagist.org/packages/pfilsx/postgresql-doctrine)
6-
[![Total Downloads](http://poser.pugx.org/pfilsx/postgresql-doctrine/downloads)](https://packagist.org/packages/pfilsx/postgresql-doctrine)
4+
![Packagist Version](https://img.shields.io/packagist/v/pfilsx/postgresql-doctrine?label=latest%20stable)
5+
![Packagist Dependency Version](https://img.shields.io/packagist/dependency-v/pfilsx/postgresql-doctrine/php)
6+
![Packagist Downloads](https://img.shields.io/packagist/dt/pfilsx/postgresql-doctrine?color=0375b6)
77

88
Description
99
------------

src/DBAL/DriverWrapper/PostgreSQLDriverWrapper.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
use Doctrine\DBAL\Platforms\AbstractPlatform;
1212
use Doctrine\DBAL\Schema\AbstractSchemaManager;
1313
use Doctrine\DBAL\Types\Type;
14-
use Doctrine\DBAL\VersionAwarePlatformDriver;
1514
use Pfilsx\PostgreSQLDoctrine\DBAL\Platform\PostgreSQLPlatform;
1615
use Pfilsx\PostgreSQLDoctrine\DBAL\Schema\PostgreSQLSchemaManager;
1716
use Pfilsx\PostgreSQLDoctrine\DBAL\Type\EnumType;
1817

19-
final class PostgreSQLDriverWrapper implements VersionAwarePlatformDriver
18+
final class PostgreSQLDriverWrapper implements Driver
2019
{
2120
private Driver $innerDriver;
2221

@@ -38,11 +37,6 @@ public function getDatabasePlatform(): PostgreSQLPlatform
3837
return new PostgreSQLPlatform();
3938
}
4039

41-
public function createDatabasePlatformForVersion($version): PostgreSQLPlatform
42-
{
43-
return new PostgreSQLPlatform();
44-
}
45-
4640
public function getSchemaManager(Connection $conn, AbstractPlatform $platform): AbstractSchemaManager
4741
{
4842
\assert($platform instanceof PostgreSQLPlatform);

src/DBAL/Platform/PostgreSQLPlatform.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getListEnumTypesSQL(): string
5151
/**
5252
* @param EnumTypeAsset $type
5353
*
54-
* @throws Exception\InvalidArgumentException
54+
* @throws InvalidArgumentException
5555
*
5656
* @return string
5757
*/
@@ -81,25 +81,23 @@ public function getAlterTypeSql(EnumTypeAsset $from, EnumTypeAsset $to): array
8181
$result = [];
8282
$typeName = $to->getQuotedName($this);
8383

84-
foreach (array_diff($toLabels, $fromLabels) as $label) {
85-
$result[] = "ALTER TYPE {$typeName} ADD VALUE {$this->quoteEnumLabel($label)}";
86-
}
87-
8884
$removedLabels = array_diff($fromLabels, $toLabels);
8985

9086
if (count($removedLabels) < 1) {
87+
foreach (array_diff($toLabels, $fromLabels) as $label) {
88+
$result[] = "ALTER TYPE {$typeName} ADD VALUE {$this->quoteEnumLabel($label)}";
89+
}
90+
9191
return $result;
9292
}
9393

94-
$self = $this;
95-
9694
$result[] = "ALTER TYPE {$typeName} RENAME TO {$typeName}_old";
9795
$result[] = $this->getCreateTypeSql($to);
9896
$result[] = $this->getCommentOnTypeSql($to);
9997

10098
foreach ($to->getUsages() as $usage) {
101-
$tableName = $this->quoteIdentifier($usage->getTable());
102-
$columnName = $this->quoteIdentifier($usage->getColumn());
99+
$tableName = $usage->getQuotedTableName($this);
100+
$columnName = $usage->getQuotedColumnName($this);
103101
if (($default = $usage->getDefault()) !== null) {
104102
$result[] = sprintf('ALTER TABLE %s ALTER COLUMN %s DROP DEFAULT', $tableName, $columnName);
105103
}

src/DBAL/Schema/EnumTypeUsageAsset.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Pfilsx\PostgreSQLDoctrine\DBAL\Schema;
66

7+
use Doctrine\DBAL\Platforms\AbstractPlatform;
8+
79
final class EnumTypeUsageAsset
810
{
911
private string $table;
@@ -12,7 +14,7 @@ final class EnumTypeUsageAsset
1214

1315
private ?string $default;
1416

15-
public function __construct(string $table, string $column, string $default = null)
17+
public function __construct(string $table, string $column, ?string $default = null)
1618
{
1719
$this->table = $table;
1820
$this->column = $column;
@@ -24,13 +26,34 @@ public function getTable(): string
2426
return $this->table;
2527
}
2628

29+
public function getQuotedTableName(AbstractPlatform $platform): string
30+
{
31+
return $this->getQuotedName($this->table, $platform);
32+
}
33+
2734
public function getColumn(): string
2835
{
2936
return $this->column;
3037
}
3138

39+
public function getQuotedColumnName(AbstractPlatform $platform): string
40+
{
41+
return $this->getQuotedName($this->column, $platform);
42+
}
43+
3244
public function getDefault(): ?string
3345
{
3446
return $this->default;
3547
}
48+
49+
private function getQuotedName(string $name, AbstractPlatform $platform): string
50+
{
51+
$keywords = $platform->getReservedKeywordsList();
52+
$parts = explode('.', $name);
53+
foreach ($parts as $k => $v) {
54+
$parts[$k] = $keywords->isKeyword($v) ? $platform->quoteIdentifier($v) : $v;
55+
}
56+
57+
return implode('.', $parts);
58+
}
3659
}

src/DBAL/Schema/PostgreSQLSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function createComparator(): Comparator
6161
return new Comparator($this->_platform);
6262
}
6363

64-
protected function selectTableColumns(string $databaseName, string $tableName = null): Result
64+
protected function selectTableColumns(string $databaseName, ?string $tableName = null): Result
6565
{
6666
$sql = 'SELECT';
6767

src/DBAL/Schema/Schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class Schema extends BaseSchema
1818
public function __construct(
1919
array $tables = [],
2020
array $sequences = [],
21-
SchemaConfig $schemaConfig = null,
21+
?SchemaConfig $schemaConfig = null,
2222
array $namespaces = [],
2323
array $types = []
2424
) {

src/DBAL/Schema/SchemaDiff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
array $createdTables = [],
2323
array $alteredTables = [],
2424
array $droppedTables = [],
25-
Schema $fromSchema = null,
25+
?Schema $fromSchema = null,
2626
array $createdSchemas = [],
2727
array $droppedSchemas = [],
2828
array $createdSequences = [],

src/DBAL/Schema/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function addColumn($name, $typeName, array $options = []): Column
2727
*
2828
* @return self
2929
*/
30-
public function modifyColumn($name, array $options, string $enumClass = null): self
30+
public function modifyColumn($name, array $options, ?string $enumClass = null): self
3131
{
3232
$column = $this->getColumn($name);
3333
$column->setOptions($options);

src/DBAL/Type/EnumType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getName(): string
4848
*
4949
* @return null|int|string
5050
*/
51-
public function convertToDatabaseValue($value, AbstractPlatform $platform): null|int|string
51+
public function convertToDatabaseValue($value, AbstractPlatform $platform): int|string|null
5252
{
5353
if ($value instanceof \BackedEnum) {
5454
return $value->value;

src/DBAL/Type/JsonModelType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
abstract class JsonModelType extends JsonType
1414
{
15-
private null|AbstractObjectNormalizer|TraceableNormalizer $normalizer = null;
15+
private AbstractObjectNormalizer|TraceableNormalizer|null $normalizer = null;
1616

1717
abstract public static function getTypeName(): string;
1818

@@ -26,7 +26,7 @@ public function getName(): string
2626
return static::getTypeName();
2727
}
2828

29-
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed
29+
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
3030
{
3131
if ($value === null) {
3232
return null;

0 commit comments

Comments
 (0)