Skip to content

Commit ed1f1c9

Browse files
committed
Merge branch '4.3.x' into 5.0.x
2 parents 8cb29ea + 83174f5 commit ed1f1c9

27 files changed

+559
-174
lines changed

UPGRADE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,25 @@ all drivers and middleware.
230230

231231
# Upgrade to 4.3
232232

233+
## Deprecated features related to primary key constraints
234+
235+
1. The `AbstractPlatform::getCreatePrimaryKeySQL()` method has been deprecated. Use the schema manager to create and
236+
alter tables.
237+
2. Building the SQL for dropping a primary key constraint via `PostgreSQLPlatform::getDropIndexSQL()` has been
238+
deprecated. Use `PostgreSQLPlatform::getDropConstraintSQL()` instead.
239+
3. Using the `Index` class to represent a primary key constraint has been deprecated, including:
240+
- Passing `true` as the `$isPrimary` constructor argument.
241+
- Using the `$_isPrimary` property and the `isPrimary()` method.
242+
243+
Use the `PrimaryKeyConstraint` class to represent a primary key constraint instead.
244+
245+
4. The following features of the `Table` class have been deprecated:
246+
- The `Table::getPrimaryKey()` method. Use `Table::getPrimaryKeyConstraint()` instead.
247+
- The `Table::setPrimaryKey()` method. Instead, pass the `$primaryKeyConstraint` argument to the constructor or add
248+
the constraint via `Table::addPrimaryKeyConstraint()`.
249+
- Using `Table::renameIndex()` to rename the primary key constraint. Use `Table::dropPrimaryKey()` and
250+
`Table::addPrimaryKeyConstraint()` instead.
251+
233252
## Deprecated invalid auto-increment column definitions on SQLite
234253

235254
The following auto-increment column definitions are deprecated in SQLite:

src/Platforms/AbstractMySQLPlatform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ protected function _getCreateTableSQL(OptionallyQualifiedName $tableName, array
249249

250250
if (isset($parameters['primary_index'])) {
251251
$elements[] = sprintf(
252-
'PRIMARY KEY(%s)',
252+
'PRIMARY KEY (%s)',
253253
implode(', ', $parameters['primary_index']->getQuotedColumns($this)),
254254
);
255255
}

src/Platforms/AbstractPlatform.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use Doctrine\DBAL\Types\Exception\TypeNotFound;
4343
use Doctrine\DBAL\Types\Exception\TypesException;
4444
use Doctrine\DBAL\Types\Type;
45+
use Doctrine\Deprecations\Deprecation;
4546

4647
use function addcslashes;
4748
use function array_map;
@@ -996,7 +997,7 @@ protected function _getCreateTableSQL(OptionallyQualifiedName $tableName, array
996997

997998
if (isset($parameters['primary_index'])) {
998999
$elements[] = sprintf(
999-
'PRIMARY KEY(%s)',
1000+
'PRIMARY KEY (%s)',
10001001
implode(', ', $parameters['primary_index']->getQuotedColumns($this)),
10011002
);
10021003
}
@@ -1145,9 +1146,18 @@ protected function getCreateIndexSQLFlags(Index $index): string
11451146

11461147
/**
11471148
* Returns the SQL to create an unnamed primary key constraint.
1149+
*
1150+
* @deprecated
11481151
*/
11491152
public function getCreatePrimaryKeySQL(Index $index, string $table): string
11501153
{
1154+
Deprecation::triggerIfCalledFromOutside(
1155+
'doctrine/dbal',
1156+
'https://github.com/doctrine/dbal/pull/6867',
1157+
'%s() is deprecated.',
1158+
__METHOD__,
1159+
);
1160+
11511161
return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . implode(', ', $index->getQuotedColumns($this)) . ')';
11521162
}
11531163

src/Platforms/OraclePlatform.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Doctrine\DBAL\TransactionIsolationLevel;
2323
use Doctrine\DBAL\Types\BinaryType;
2424
use Doctrine\DBAL\Types\Types;
25+
use Doctrine\Deprecations\Deprecation;
2526
use InvalidArgumentException;
2627

2728
use function array_merge;
@@ -131,8 +132,16 @@ public function getBitOrComparisonExpression(string $value1, string $value2): st
131132
. '+' . $value2 . ')';
132133
}
133134

135+
/** @deprecated */
134136
public function getCreatePrimaryKeySQL(Index $index, string $table): string
135137
{
138+
Deprecation::triggerIfCalledFromOutside(
139+
'doctrine/dbal',
140+
'https://github.com/doctrine/dbal/pull/6867',
141+
'%s() is deprecated.',
142+
__METHOD__,
143+
);
144+
136145
return 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $index->getObjectName()->toSQL($this)
137146
. ' PRIMARY KEY (' . implode(', ', $index->getQuotedColumns($this)) . ')';
138147
}

src/Platforms/PostgreSQLPlatform.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\DBAL\Schema\TableDiff;
1818
use Doctrine\DBAL\TransactionIsolationLevel;
1919
use Doctrine\DBAL\Types\Types;
20+
use Doctrine\Deprecations\Deprecation;
2021
use UnexpectedValueException;
2122

2223
use function array_merge;
@@ -363,6 +364,14 @@ public function getDropIndexSQL(string $name, string $table): string
363364
}
364365

365366
if ($name === '"primary"' || $name === $primaryKeyName) {
367+
Deprecation::triggerIfCalledFromOutside(
368+
'doctrine/dbal',
369+
'https://github.com/doctrine/dbal/pull/6867',
370+
'Building the SQL for dropping primary key constraint via %s() is deprecated. Use'
371+
. ' getDropConstraintSQL() instead.',
372+
__METHOD__,
373+
);
374+
366375
return $this->getDropConstraintSQL($primaryKeyName, $table);
367376
}
368377

@@ -387,7 +396,7 @@ protected function _getCreateTableSQL(OptionallyQualifiedName $tableName, array
387396

388397
if (isset($parameters['primary_index'])) {
389398
$elements[] = sprintf(
390-
'PRIMARY KEY(%s)',
399+
'PRIMARY KEY (%s)',
391400
implode(', ', $parameters['primary_index']->getQuotedColumns($this)),
392401
);
393402
}

src/Platforms/SQLServerPlatform.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder;
2323
use Doctrine\DBAL\TransactionIsolationLevel;
2424
use Doctrine\DBAL\Types\Types;
25+
use Doctrine\Deprecations\Deprecation;
2526
use InvalidArgumentException;
2627

2728
use function array_map;
@@ -249,8 +250,16 @@ protected function _getCreateTableSQL(OptionallyQualifiedName $tableName, array
249250
return array_merge($sql, $commentsSql, $defaultConstraintsSql);
250251
}
251252

253+
/** @deprecated */
252254
public function getCreatePrimaryKeySQL(Index $index, string $table): string
253255
{
256+
Deprecation::triggerIfCalledFromOutside(
257+
'doctrine/dbal',
258+
'https://github.com/doctrine/dbal/pull/6867',
259+
'%s() is deprecated.',
260+
__METHOD__,
261+
);
262+
254263
$sql = 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY';
255264

256265
if ($index->hasFlag('nonclustered')) {

src/Platforms/SQLitePlatform.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ protected function _getCreateTableSQL(OptionallyQualifiedName $tableName, array
285285
$primaryKeyColumns = $parameters['primary_index']->getQuotedColumns($this);
286286

287287
$elements[] = sprintf(
288-
'PRIMARY KEY(%s)',
288+
'PRIMARY KEY (%s)',
289289
implode(', ', $primaryKeyColumns),
290290
);
291291
}
@@ -588,6 +588,7 @@ public function getDropTablesSQL(array $tables): array
588588
return $sql;
589589
}
590590

591+
/** @deprecated */
591592
public function getCreatePrimaryKeySQL(Index $index, string $table): string
592593
{
593594
throw NotSupported::new(__METHOD__);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Schema\Exception;
6+
7+
use Doctrine\DBAL\Schema\SchemaException;
8+
use LogicException;
9+
10+
final class InvalidPrimaryKeyConstraintDefinition extends LogicException implements SchemaException
11+
{
12+
public static function columnNamesNotSet(): self
13+
{
14+
return new self('Primary key constraint column names are not set.');
15+
}
16+
}

src/Schema/Exception/InvalidState.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
use Doctrine\DBAL\Schema\SchemaException;
88
use LogicException;
99

10+
use function sprintf;
11+
1012
final class InvalidState extends LogicException implements SchemaException
1113
{
14+
public static function tableHasInvalidPrimaryKeyConstraint(string $tableName): self
15+
{
16+
return new self(sprintf('Table "%s" has invalid primary key constraint.', $tableName));
17+
}
1218
}

src/Schema/Index.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\DBAL\Schema\Name\Parser\UnqualifiedNameParser;
1313
use Doctrine\DBAL\Schema\Name\Parsers;
1414
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
15+
use Doctrine\Deprecations\Deprecation;
1516

1617
use function array_filter;
1718
use function array_keys;
@@ -34,6 +35,7 @@ final class Index extends AbstractNamedObject
3435

3536
private readonly bool $_isUnique;
3637

38+
/** @deprecated Use {@see PrimaryKeyConstraint()} instead. */
3739
private readonly bool $_isPrimary;
3840

3941
/**
@@ -69,6 +71,14 @@ public function __construct(
6971
throw InvalidIndexDefinition::columnNamesNotSet();
7072
}
7173

74+
if ($isPrimary) {
75+
Deprecation::triggerIfCalledFromOutside(
76+
'doctrine/dbal',
77+
'https://github.com/doctrine/dbal/pull/6867',
78+
'Declaring an index as primary is deprecated. Use PrimaryKeyConstraint instead.',
79+
);
80+
}
81+
7282
$this->_isUnique = $isUnique || $isPrimary;
7383
$this->_isPrimary = $isPrimary;
7484

@@ -144,7 +154,7 @@ public function getQuotedColumns(AbstractPlatform $platform): array
144154
return $columns;
145155
}
146156

147-
/** @return array<int, string> */
157+
/** @return non-empty-list<string> */
148158
public function getUnquotedColumns(): array
149159
{
150160
return array_map($this->trimQuotes(...), $this->getColumns());
@@ -163,8 +173,15 @@ public function isUnique(): bool
163173
return $this->_isUnique;
164174
}
165175

176+
/** @deprecated Use {@see PrimaryKeyConstraint()} instead. */
166177
public function isPrimary(): bool
167178
{
179+
Deprecation::triggerIfCalledFromOutside(
180+
'doctrine/dbal',
181+
'https://github.com/doctrine/dbal/pull/6867',
182+
'Checking whether an index is primary is deprecated. Use PrimaryKeyConstraint instead.',
183+
);
184+
168185
return $this->_isPrimary;
169186
}
170187

0 commit comments

Comments
 (0)