Skip to content

Commit ef2f9b6

Browse files
committed
Merge branch '4.1.x' into 5.0.x
* 4.1.x: Prepare 3.9.0 and 4.1.0 (#6492) Deprecate support for Postgres 10 and 11 (#6495) Document the new PostgreSQL120Platform (#6494) fix #6198: stop considering generated column definition as being its default value (#6199) Fix condition on Ascii String for SQL Server (#6389) Add DBTypes that are missing for TypeMapping (#6463)
2 parents 00837c0 + 2377cd4 commit ef2f9b6

13 files changed

+177
-40
lines changed

.doctrine-project.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,35 @@
1111
"slug": "latest",
1212
"upcoming": true
1313
},
14+
{
15+
"name": "4.2",
16+
"branchName": "4.2.x",
17+
"slug": "4.2",
18+
"upcoming": true
19+
},
1420
{
1521
"name": "4.1",
1622
"branchName": "4.1.x",
1723
"slug": "4.1",
18-
"upcoming": true
24+
"current": true
1925
},
2026
{
2127
"name": "4.0",
2228
"branchName": "4.0.x",
2329
"slug": "4.0",
24-
"current": true
30+
"maintained": false
2531
},
2632
{
2733
"name": "3.9",
2834
"branchName": "3.9.x",
2935
"slug": "3.9",
30-
"upcoming": true
36+
"maintained": true
3137
},
3238
{
3339
"name": "3.8",
3440
"branchName": "3.8.x",
3541
"slug": "3.8",
36-
"maintained": true
42+
"maintained": false
3743
},
3844
{
3945
"name": "3.7",

README.md

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Doctrine DBAL
22

3-
| [5.0-dev][5.0] | [4.1-dev][4.1] | [4.0][4.0] | [3.9-dev][3.9] | [3.8][3.8] |
4-
|:---------------------------------------------------:|:---------------------------------------------------:|:---------------------------------------------------:|:---------------------------------------------------:|:---------------------------------------------------:|
5-
| [![GitHub Actions][GA 5.0 image]][GA 5.0] | [![GitHub Actions][GA 4.1 image]][GA 4.1] | [![GitHub Actions][GA 4.0 image]][GA 4.0] | [![GitHub Actions][GA 3.9 image]][GA 3.9] | [![GitHub Actions][GA 3.8 image]][GA 3.8] |
6-
| [![AppVeyor][AppVeyor 5.0 image]][AppVeyor 5.0] | [![AppVeyor][AppVeyor 4.1 image]][AppVeyor 4.1] | [![AppVeyor][AppVeyor 4.0 image]][AppVeyor 4.0] | [![AppVeyor][AppVeyor 3.9 image]][AppVeyor 3.9] | [![AppVeyor][AppVeyor 3.8 image]][AppVeyor 3.8] |
7-
| [![Code Coverage][Coverage 5.0 image]][CodeCov 5.0] | [![Code Coverage][Coverage 4.1 image]][CodeCov 4.1] | [![Code Coverage][Coverage 4.0 image]][CodeCov 4.0] | [![Code Coverage][Coverage 3.9 image]][CodeCov 3.9] | [![Code Coverage][Coverage 3.8 image]][CodeCov 3.8] |
8-
| N/A | N/A | [![Type Coverage][TypeCov image]][TypeCov] | N/A | |
3+
| [5.0-dev][5.0] | [4.2-dev][4.2] | [4.1][4.1] | [3.9][3.9] |
4+
|:---------------------------------------------------:|:---------------------------------------------------:|:---------------------------------------------------:|:---------------------------------------------------:|
5+
| [![GitHub Actions][GA 5.0 image]][GA 5.0] | [![GitHub Actions][GA 4.2 image]][GA 4.2] | [![GitHub Actions][GA 4.1 image]][GA 4.1] | [![GitHub Actions][GA 3.9 image]][GA 3.9] |
6+
| [![AppVeyor][AppVeyor 5.0 image]][AppVeyor 5.0] | [![AppVeyor][AppVeyor 4.2 image]][AppVeyor 4.2] | [![AppVeyor][AppVeyor 4.1 image]][AppVeyor 4.1] | [![AppVeyor][AppVeyor 3.9 image]][AppVeyor 3.9] |
7+
| [![Code Coverage][Coverage 5.0 image]][CodeCov 5.0] | [![Code Coverage][Coverage 4.2 image]][CodeCov 4.2] | [![Code Coverage][Coverage 4.1 image]][CodeCov 4.1] | [![Code Coverage][Coverage 3.9 image]][CodeCov 3.9] |
8+
| N/A | N/A | [![Type Coverage][TypeCov image]][TypeCov] | N/A |
99

1010
Powerful ***D***ata***B***ase ***A***bstraction ***L***ayer with many features for database schema introspection and schema management.
1111

@@ -23,21 +23,21 @@ Powerful ***D***ata***B***ase ***A***bstraction ***L***ayer with many features f
2323
[GA 5.0]: https://github.com/doctrine/dbal/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A5.0.x
2424
[GA 5.0 image]: https://github.com/doctrine/dbal/workflows/Continuous%20Integration/badge.svg?branch=5.0.x
2525

26+
[Coverage 4.2 image]: https://codecov.io/gh/doctrine/dbal/branch/4.2.x/graph/badge.svg
27+
[4.2]: https://github.com/doctrine/dbal/tree/4.2.x
28+
[CodeCov 4.2]: https://codecov.io/gh/doctrine/dbal/branch/4.2.x
29+
[AppVeyor 4.2]: https://ci.appveyor.com/project/doctrine/dbal/branch/4.2.x
30+
[AppVeyor 4.2 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/4.2.x?svg=true
31+
[GA 4.2]: https://github.com/doctrine/dbal/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A4.2.x
32+
[GA 4.2 image]: https://github.com/doctrine/dbal/workflows/Continuous%20Integration/badge.svg?branch=4.2.x
33+
2634
[Coverage 4.1 image]: https://codecov.io/gh/doctrine/dbal/branch/4.1.x/graph/badge.svg
2735
[4.1]: https://github.com/doctrine/dbal/tree/4.1.x
2836
[CodeCov 4.1]: https://codecov.io/gh/doctrine/dbal/branch/4.1.x
2937
[AppVeyor 4.1]: https://ci.appveyor.com/project/doctrine/dbal/branch/4.1.x
3038
[AppVeyor 4.1 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/4.1.x?svg=true
3139
[GA 4.1]: https://github.com/doctrine/dbal/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A4.1.x
3240
[GA 4.1 image]: https://github.com/doctrine/dbal/workflows/Continuous%20Integration/badge.svg?branch=4.1.x
33-
34-
[Coverage 4.0 image]: https://codecov.io/gh/doctrine/dbal/branch/4.0.x/graph/badge.svg
35-
[4.0]: https://github.com/doctrine/dbal/tree/4.0.x
36-
[CodeCov 4.0]: https://codecov.io/gh/doctrine/dbal/branch/4.0.x
37-
[AppVeyor 4.0]: https://ci.appveyor.com/project/doctrine/dbal/branch/4.0.x
38-
[AppVeyor 4.0 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/4.0.x?svg=true
39-
[GA 4.0]: https://github.com/doctrine/dbal/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A4.0.x
40-
[GA 4.0 image]: https://github.com/doctrine/dbal/workflows/Continuous%20Integration/badge.svg?branch=4.0.x
4141
[TypeCov]: https://shepherd.dev/github/doctrine/dbal
4242
[TypeCov image]: https://shepherd.dev/github/doctrine/dbal/coverage.svg
4343

@@ -48,11 +48,3 @@ Powerful ***D***ata***B***ase ***A***bstraction ***L***ayer with many features f
4848
[AppVeyor 3.9 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/3.9.x?svg=true
4949
[GA 3.9]: https://github.com/doctrine/dbal/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A3.9.x
5050
[GA 3.9 image]: https://github.com/doctrine/dbal/workflows/Continuous%20Integration/badge.svg?branch=3.9.x
51-
52-
[Coverage 3.8 image]: https://codecov.io/gh/doctrine/dbal/branch/3.8.x/graph/badge.svg
53-
[3.8]: https://github.com/doctrine/dbal/tree/3.8.x
54-
[CodeCov 3.8]: https://codecov.io/gh/doctrine/dbal/branch/3.8.x
55-
[AppVeyor 3.8]: https://ci.appveyor.com/project/doctrine/dbal/branch/3.8.x
56-
[AppVeyor 3.8 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/3.8.x?svg=true
57-
[GA 3.8]: https://github.com/doctrine/dbal/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A3.8.x
58-
[GA 3.8 image]: https://github.com/doctrine/dbal/workflows/Continuous%20Integration/badge.svg?branch=3.8.x

UPGRADE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ all drivers and middleware.
2525
The `TableDiff` methods `getModifiedColumns()` and `getRenamedColumns()` have been merged into a single
2626
method `getChangedColumns()`. Use this method instead.
2727

28-
## Deprecated support for MariaDB 10.4 and MySQL 5.7
28+
## Deprecated support for MariaDB 10.4, MySQL 5.7 and Postgres 10 + 11
2929

3030
* Upgrade to MariaDB 10.5 or later.
3131
* Upgrade to MySQL 8.0 or later.
32+
* Upgrade to Postgres 12 or later.
3233

3334
## Add `Result::getColumnName()`
3435

docs/en/reference/platforms.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ Microsoft SQL Server
5656
PostgreSQL
5757
^^^^^^^^^^
5858

59-
- ``PostgreSQLPlatform`` for version 9.4 and above.
60-
- ``PostgreSQL100Platform`` for version 10.0 and above.
59+
- ``PostgreSQLPlatform`` for version 10.0 and above.
60+
- ``PostgreSQL120Platform`` for version 12.0 and above.
6161

6262
IBM DB2
6363
^^^^^^^

psalm.xml.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@
4242
<file name="src/Driver/OCI8/ConvertPositionalToNamedPlaceholders.php"/>
4343
</errorLevel>
4444
</ConflictingReferenceConstraint>
45+
<DeprecatedClass>
46+
<errorLevel type="suppress">
47+
<!--
48+
See https://github.com/doctrine/dbal/pull/6343
49+
TODO: remove in 5.0.0
50+
-->
51+
<referencedClass name="Doctrine\DBAL\Platforms\PostgreSQL120Platform" />
52+
</errorLevel>
53+
</DeprecatedClass>
4554
<DeprecatedMethod>
4655
<errorLevel type="suppress">
4756
<!--

src/Driver/AbstractPostgreSQLDriver.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
use Doctrine\DBAL\Driver;
88
use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
99
use Doctrine\DBAL\Driver\API\PostgreSQL\ExceptionConverter;
10+
use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion;
11+
use Doctrine\DBAL\Platforms\PostgreSQL120Platform;
1012
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
1113
use Doctrine\DBAL\ServerVersionProvider;
14+
use Doctrine\Deprecations\Deprecation;
15+
16+
use function preg_match;
17+
use function version_compare;
1218

1319
/**
1420
* Abstract base implementation of the {@see Driver} interface for PostgreSQL based drivers.
@@ -17,6 +23,30 @@ abstract class AbstractPostgreSQLDriver implements Driver
1723
{
1824
public function getDatabasePlatform(ServerVersionProvider $versionProvider): PostgreSQLPlatform
1925
{
26+
$version = $versionProvider->getServerVersion();
27+
28+
if (preg_match('/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/', $version, $versionParts) === 0) {
29+
throw InvalidPlatformVersion::new(
30+
$version,
31+
'<major_version>.<minor_version>.<patch_version>',
32+
);
33+
}
34+
35+
$majorVersion = $versionParts['major'];
36+
$minorVersion = $versionParts['minor'] ?? 0;
37+
$patchVersion = $versionParts['patch'] ?? 0;
38+
$version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion;
39+
40+
if (version_compare($version, '12.0', '>=')) {
41+
return new PostgreSQL120Platform();
42+
}
43+
44+
Deprecation::trigger(
45+
'doctrine/dbal',
46+
'https://github.com/doctrine/dbal/pull/6495',
47+
'Support for Postgres < 12 is deprecated and will be removed in DBAL 5',
48+
);
49+
2050
return new PostgreSQLPlatform();
2151
}
2252

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Platforms;
6+
7+
/**
8+
* Provides the behavior, features and SQL dialect of the PostgreSQL 12.0 database platform.
9+
*
10+
* @deprecated This class will be removed once support for Postgres < 12 is dropped.
11+
*/
12+
class PostgreSQL120Platform extends PostgreSQLPlatform
13+
{
14+
public function getDefaultColumnValueSQLSnippet(): string
15+
{
16+
// in case of GENERATED ALWAYS AS (foobar) STORED column (added in PostgreSQL 12.0)
17+
// PostgreSQL's pg_get_expr(adbin, adrelid) will return the 'foobar' part
18+
// which is not the 'default' value of the column but its 'definition'
19+
// so in that case we force it to NULL as DBAL will use that column only for the
20+
// 'default' value
21+
return <<<'SQL'
22+
SELECT
23+
CASE
24+
WHEN a.attgenerated = 's' THEN NULL
25+
ELSE pg_get_expr(adbin, adrelid)
26+
END
27+
FROM pg_attrdef
28+
WHERE c.oid = pg_attrdef.adrelid
29+
AND pg_attrdef.adnum=a.attnum
30+
SQL;
31+
}
32+
}

src/Platforms/PostgreSQLPlatform.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
use function trim;
3434

3535
/**
36-
* Provides the behavior, features and SQL dialect of the PostgreSQL 9.4+ database platform.
36+
* Provides the behavior, features and SQL dialect of the PostgreSQL database platform
37+
* of the oldest supported version.
3738
*/
3839
class PostgreSQLPlatform extends AbstractPlatform
3940
{
@@ -676,6 +677,19 @@ public function getTruncateTableSQL(string $tableName, bool $cascade = false): s
676677
return $sql;
677678
}
678679

680+
/**
681+
* Get the snippet used to retrieve the default value for a given column
682+
*/
683+
public function getDefaultColumnValueSQLSnippet(): string
684+
{
685+
return <<<'SQL'
686+
SELECT pg_get_expr(adbin, adrelid)
687+
FROM pg_attrdef
688+
WHERE c.oid = pg_attrdef.adrelid
689+
AND pg_attrdef.adnum=a.attnum
690+
SQL;
691+
}
692+
679693
protected function initializeDoctrineTypeMappings(): void
680694
{
681695
$this->doctrineTypeMapping = [

src/Platforms/SQLServerPlatform.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,12 +1080,14 @@ protected function initializeDoctrineTypeMappings(): void
10801080
'smalldatetime' => Types::DATETIME_MUTABLE,
10811081
'smallint' => Types::SMALLINT,
10821082
'smallmoney' => Types::INTEGER,
1083+
'sysname' => Types::STRING,
10831084
'text' => Types::TEXT,
10841085
'time' => Types::TIME_MUTABLE,
10851086
'tinyint' => Types::SMALLINT,
10861087
'uniqueidentifier' => Types::GUID,
10871088
'varbinary' => Types::BINARY,
10881089
'varchar' => Types::STRING,
1090+
'xml' => Types::TEXT,
10891091
];
10901092
}
10911093

src/Schema/PostgreSQLSchemaManager.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,13 @@ protected function selectTableNames(string $databaseName): Result
411411

412412
protected function selectTableColumns(string $databaseName, ?string $tableName = null): Result
413413
{
414-
$sql = 'SELECT';
414+
$sql = 'SELECT ';
415415

416416
if ($tableName === null) {
417-
$sql .= ' c.relname AS table_name, n.nspname AS schema_name,';
417+
$sql .= 'c.relname AS table_name, n.nspname AS schema_name,';
418418
}
419419

420-
$sql .= <<<'SQL'
420+
$sql .= sprintf(<<<'SQL'
421421
a.attnum,
422422
quote_ident(a.attname) AS field,
423423
t.typname AS type,
@@ -434,11 +434,7 @@ protected function selectTableColumns(string $databaseName, ?string $tableName =
434434
AND pg_index.indkey[0] = a.attnum
435435
AND pg_index.indisprimary = 't'
436436
) AS pri,
437-
(SELECT pg_get_expr(adbin, adrelid)
438-
FROM pg_attrdef
439-
WHERE c.oid = pg_attrdef.adrelid
440-
AND pg_attrdef.adnum=a.attnum
441-
) AS default,
437+
(%s) AS default,
442438
(SELECT pg_description.description
443439
FROM pg_description WHERE pg_description.objoid = c.oid AND a.attnum = pg_description.objsubid
444440
) AS comment
@@ -453,7 +449,7 @@ protected function selectTableColumns(string $databaseName, ?string $tableName =
453449
ON d.objid = c.oid
454450
AND d.deptype = 'e'
455451
AND d.classid = (SELECT oid FROM pg_class WHERE relname = 'pg_class')
456-
SQL;
452+
SQL, $this->platform->getDefaultColumnValueSQLSnippet());
457453

458454
$conditions = array_merge([
459455
'a.attnum > 0',

0 commit comments

Comments
 (0)